Geckoview in android app crashing with error "java.lang.Exception: Error loading sqlite libraries"

1.1k Views Asked by At

I already read lots of articles and howtos here and elsewhere concerning geckoview, but i didn't find any help for my problem. I integrated geckoview in my android app (as an replacement for webview). I did everything as explained in howtos, but in the moment, the activity wants to show up, the app crashes, with the error "java.lang.Exception: Error loading sqlite libraries". Could anybody help me?

build.gradle (module)

ext {
    geckoviewChannel = "nightly"
    geckoviewVersion = "86.0.20210124091450"
}

repositories {
    maven {
        url "https://maven.mozilla.org/maven2/"
    }
}

activity xml

<org.mozilla.geckoview.GeckoView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/geckoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

activity top

import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoView;

activity onCreate

        boolean doGecko=true;
        myGeckoView = findViewById(R.id.geckoview);
        if (doGecko) {
            Log.d(logTag, "starting GeckoView: "+myGeckoView);
            try {
                if (myGeckoSession==null) {
                    Log.d(logTag, "myGeckoSession = new GeckoSession()");
                    myGeckoSession = new GeckoSession();
                }
                Log.d(logTag, "GeckoSession: "+myGeckoSession);

                if (myGeckoRuntime==null ) {
                    myGeckoRuntime = GeckoRuntime.create(this);
                    Log.d(logTag, "created GeckoRuntime: "+myGeckoRuntime );
                } else {
                    myGeckoRuntime = GeckoRuntime.getDefault(this);
                    Log.d(logTag, "getting default GeckoRuntime: "+myGeckoRuntime );
                }

                Log.d(logTag, "myGeckoSession.open(myGeckoRuntime)");
                myGeckoSession.open(myGeckoRuntime);

                Log.d(logTag, "myGeckoview.setSession(myGeckoSession)");
                myGeckoView.setSession(myGeckoSession);
                Log.d(logTag, "loading url");
                myGeckoSession.loadUri("http://www.google.de");
            } catch (Exception e) {
                Log.d(logTag, "error "+e.toString() );
            }
        } else {
            myGeckoView.setVisibility(View.INVISIBLE);
        }

stack trace

2021-01-25 11:14:18.011 4815-4883/com.test.de.browseme E/GeckoLibLoad: Load sqlite start
2021-01-25 11:14:18.011 4815-4883/com.test.de.browseme E/GeckoLibLoad: Couldn't get a handle to libnss3!
2021-01-25 11:14:18.011 4815-4883/com.test.de.browseme E/GeckoLibLoad: Throw
2021-01-25 11:14:18.011 4815-4883/com.test.de.browseme E/GeckoLibLoad: Load sqlite done
2021-01-25 11:14:18.013 4815-4883/com.test.de.browseme E/AndroidRuntime: FATAL EXCEPTION: Gecko
    Process: com.test.de.browseme, PID: 4815
    java.lang.Exception: Error loading sqlite libraries
        at org.mozilla.gecko.mozglue.GeckoLoader.loadSQLiteLibsNative(Native Method)
        at org.mozilla.gecko.mozglue.GeckoLoader.loadSQLiteLibs(GeckoLoader.java:204)
        at org.mozilla.gecko.GeckoThread.loadGeckoLibs(GeckoThread.java:247)
        at org.mozilla.gecko.GeckoThread.initGeckoEnvironment(GeckoThread.java:267)
        at org.mozilla.gecko.GeckoThread.run(GeckoThread.java:430)
4

There are 4 best solutions below

0
On

In my case this crash occurred only in release mode. So I sat on this problem for a whole day until I got the idea to exclude the lib from proguard - et voila that was the problem. Proguard obfuscated parts it shouldn't obfuscate. Just add this to your proguard-rules.pro:

-keep class org.mozilla.** {*;}

Maybe that's not the best way, but I haven't found a better solution.

0
On

This looks like issue 116 https://github.com/mozilla/geckoview/issues/116

Go to your manifest and add this under the application area:

android:extractNativeLibs="true"
0
On

I added android:extractNativeLibs="true" to the manifest, and according to this comment, I also added:

android.bundle.enableUncompressedNativeLibs=false

to gradle.properties, which fixed my issue locally. I don't know what will happen when I upload to Google Play.

0
On

my working config to fix this issue and some firefox geckoview errors like

Could not find mozglue path.                                                                                                      at org.mozilla.gecko.mozglue.GeckoLoader site:stackoverflow.com
<application
        android:name=".CoreApp"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:requestLegacyExternalStorage="true"
        android:supportsRtl="true"
        android:theme="@style/Theme.Reply.DayNight"
        android:extractNativeLibs="true"></application>

in gradle

android {
    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
        merge "**/LICENSE.txt"
        merge "**/NOTICE.txt"
        exclude "**/*.ignore"
        exclude "**/*.ignored"
        // kotlin coroutines
        resources.excludes += "DebugProbesKt.bin"
        exclude("META-INF/DEPENDENCIES")
        exclude("META-INF/LICENSE")
        exclude("META-INF/license.txt")
        exclude("META-INF/NOTICE.txt")
        exclude("META-INF/notice.txt")
        exclude("META-INF/ASL2.0")
        exclude("META-INF/*.kotlin_module")
        exclude('mozilla/public-suffix-list.txt')
    }
}

note: MULTIDEX must be enabled on your android app project