Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting java.lang.UnsatisfiedLinkError #635

Open
UKMIITB opened this issue Aug 25, 2023 · 11 comments
Open

Getting java.lang.UnsatisfiedLinkError #635

UKMIITB opened this issue Aug 25, 2023 · 11 comments

Comments

@UKMIITB
Copy link

UKMIITB commented Aug 25, 2023

Expected Behavior

App should not crash

Actual Behavior

App is crashing for some devices as per crashlytics report

Steps to Reproduce

SQLCipher version (can be identified by executing PRAGMA cipher_version;):

SQLCipher for Android version:
implementation "net.zetetic:android-database-sqlcipher:4.5.4"

Are you able to reproduce this issue within the SQLCipher for Android test suite?

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system_ext/lib64/libsqlcipher.so" needed or dlopened by "/apex/com.android.art/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
at java.lang.Runtime.loadLibrary0(Runtime.java:998)
at java.lang.System.loadLibrary(System.java:1661)
at net.sqlcipher.database.SQLiteDatabase$1.loadLibraries(SQLiteDatabase.java:230)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:247)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:226)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:219)
at net.sqlcipher.database.SupportHelper.(SupportHelper.java:31)
at net.sqlcipher.database.SupportFactory.create(SupportFactory.java:43)

Note: If you are not posting a specific issue for the SQLCipher library, please post your question to the SQLCipher discuss site. Thanks!

@UKMIITB
Copy link
Author

UKMIITB commented Aug 25, 2023

Getting crash for some devices.
Not able to reproduce this but its happening on production.
We ship the app using aab bundle

@developernotes
Copy link
Member

Hi @UKMIITB,

For some devices which present UnsatisfiedLinkError exceptions, we've received mixed reports that the ReLinker project is helpful. The SQLiteDatabase.loadLibs method has an overload which accepts a LibraryLoader interface allowing you to interface with ReLinker. Would you give that a try?

@UKMIITB
Copy link
Author

UKMIITB commented Aug 26, 2023

@developernotes
Sure will try this. But before that I have one query

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/app/~~II4tLM-0_RLY-7OguisUXw==/com.naviapp-gFZaPbri6blefum1gu84QA==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libsqlcipher.so" not found
       at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
       at java.lang.Runtime.loadLibrary0(Runtime.java:998)
       at java.lang.System.loadLibrary(System.java:1661)
       at net.sqlcipher.database.SQLiteDatabase$1.loadLibraries(SQLiteDatabase.java:230)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:247)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:226)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:219)
       at net.sqlcipher.database.SupportHelper.<init>(SupportHelper.java:31)
       at net.sqlcipher.database.SupportFactory.create(SupportFactory.java:43)

At the beginning we faced this error. We upload app as aab bundle on playstore. And for some devices in the split .so file was not found.
For this in project gradle.properties we added android.disableAutomaticComponentCreation=true
And this seems to have fixed the current issue.

But now we are getting a different issue as mentioned above

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system_ext/lib64/libsqlcipher.so" needed or dlopened by "/apex/com.android.art/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"

Does ReLinker project fixes this current issue or will it fix both the issues ?
Can you share some more insight on these 2 issues

@UKMIITB
Copy link
Author

UKMIITB commented Aug 26, 2023

@developernotes
Copy link
Member

Hi @UKMIITB,

Are you building a custom Android image? I don't recall seeing an error relating to libnativeloader.so reporting an issue. Are you building a custom Android image? One thing to note, if your application is being deployed as an AppBundle, you might also consider trying the usage of SplitInstallHelper.loadLibrary(...) inside your LibraryLoader implementation provided to SQLiteDatabase.loadLibs.

@UKMIITB
Copy link
Author

UKMIITB commented Aug 28, 2023

@developernotes
No not building any custom android image.
Just added this dependency implementation "net.zetetic:android-database-sqlcipher:4.5.4"

Generating a passphrase
And then building

Room.databaseBuilder(
            context,
            EncryptedDatabase::class.java,
            ENCRYPTED_DATABASE_NAME
        )
            .openHelperFactory(SupportFactory(passphrase))
            .build()

Can you elaborate more on how to use SplitInstallHelper.loadLibrary(...) with SQLCipher

@developernotes
Copy link
Member

Hi @UKMIITB,

You need to invoke SQLiteDatabase.loadLibs(...) prior to a database operation as this loads the native library necessary for SQLCipher for Android. The call to loadLibs accepts a LibraryLoader implementation, by default it uses something like this:

loadLibs(context, workingDir, new LibraryLoader() {
        @Override
        public void loadLibraries(String... libNames) {
          for (String libName : libNames) {
            System.loadLibrary(libName);
          }
        }
      });

In your case, you can provide an alternative LibraryLoader in your call to loadLibs(...) in which you would invoke SplitInstallHelper.loadLibrary(...) instead of using System.loadLibrary(...).

@goldfish07
Copy link

@developernotes Sure will try this. But before that I have one query

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/app/~~II4tLM-0_RLY-7OguisUXw==/com.naviapp-gFZaPbri6blefum1gu84QA==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libsqlcipher.so" not found
       at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
       at java.lang.Runtime.loadLibrary0(Runtime.java:998)
       at java.lang.System.loadLibrary(System.java:1661)
       at net.sqlcipher.database.SQLiteDatabase$1.loadLibraries(SQLiteDatabase.java:230)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:247)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:226)
       at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:219)
       at net.sqlcipher.database.SupportHelper.<init>(SupportHelper.java:31)
       at net.sqlcipher.database.SupportFactory.create(SupportFactory.java:43)

At the beginning we faced this error. We upload app as aab bundle on playstore. And for some devices in the split .so file was not found. For this in project gradle.properties we added android.disableAutomaticComponentCreation=true And this seems to have fixed the current issue.

But now we are getting a different issue as mentioned above

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "/system_ext/lib64/libsqlcipher.so" needed or dlopened by "/apex/com.android.art/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"

Does ReLinker project fixes this current issue or will it fix both the issues ? Can you share some more insight on these 2 issues

add packagingOptions inside android{} in app-level gradle file
packagingOptions { jniLibs { useLegacyPackaging = true } }

@developernotes
Copy link
Member

Hi @goldfish07,

Unfortunately, I am unaware if ReLinker resolves this specific issue. We have received sporadic reports of success when using ReLinker.

Another option to investigate within your application is the use of the android:extractNativeLibs setting within your application manifest, and the related useLegacyPackaging option in build.gradle. If you adjust your usage of those settings, does the behavior change?

@goldfish07
Copy link

@developernotes

Fatal Exception: java.lang.UnsatisfiedLinkError may occur when user sideloads app from third-party , useLegacyPackaging do resolve issue in app bundle. and i never used ReLinker

@developernotes
Copy link
Member

Hi @goldfish07,

I'm glad to hear that useLegacyPackaging was helpful for you, thanks for sharing your update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants