Willena / sqlite-jdbc-crypt

SQLite JDBC Driver with encryption support
Apache License 2.0
172 stars 33 forks source link

java.lang.UnsatisfiedLinkError on Android #57

Closed schdief06 closed 2 years ago

schdief06 commented 2 years ago

Hi,

I'm about to move from sqldroid to your library, as I want to use encrypted files in an Android App. When I open an connection with the code snippet you provided I get the following exception:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libsqlitejdbc.so" not found at java.lang.Runtime.loadLibrary0(Runtime.java:1087) at java.lang.Runtime.loadLibrary0(Runtime.java:1008) at java.lang.System.loadLibrary(System.java:1664) at org.sqlite.core.NativeDB.<clinit>(NativeDB.java:34) at org.sqlite.core.NativeDB.load(NativeDB.java:54) at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:256) at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:62) at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:23) at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19) at org.sqlite.JDBC.createConnection(JDBC.java:104) at org.sqlite.JDBC.connect(JDBC.java:77) at java.sql.DriverManager.getConnection(DriverManager.java:580) at java.sql.DriverManager.getConnection(DriverManager.java:236)

Line where I open the connection: this.connection = DriverManager.getConnection("jdbc:sqlite:"+path);

Line from my build.gradle: implementation 'io.github.willena:sqlite-jdbc:3.37.2'

Am I doing anything wrong? The same line of code works fine, when in "desktop"-java Thanks for your help

Willena commented 2 years ago

First of, I'm not an expert of android development. Here is what I was saying a similar issue: https://github.com/Willena/sqlite-jdbc-crypt/issues/48#issuecomment-913041722

I've never used it on android, but:

  1. You should import the library usual
  2. If you are getting an Error for missing library, Either the platform is not precompiled [...] or the binary file is not included as resource during the build time. If I remember well, it might be necessary [to create a libs folder or] to extract the DLL for android arm in the libs folder of your project (do not open the jar, just download them from releases, all DLL are available as a zip file).

I also found this Stack Overflow answer: https://stackoverflow.com/a/6295760/4346098

Hope it helped :)

schdief06 commented 2 years ago

Thanks for your answer. The posts in the links aren't completly right. But they helped me to find a solution. If anyone else is having the same issue:

  1. Download the .jar File and open it with 7zip/winrar or similar
  2. Go to org/sqlite/native/Linux-Android
  3. Copy all folders to the jniLibs-Folder of your Android-projekt (project/src/main/jniLibs; Complete folder structure: https://stackoverflow.com/a/24360361/9046587)

Additionally NDK has to be installed in Android Studio: https://developer.android.com/studio/projects/install-ndk

Hope this helps somebody.