sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

Failed to load native library when running in Termux

Open AdorableParker opened this issue 3 years ago • 5 comments

This works fine on Windows, according to the README.md, it should also work adaptively on Termux, but it doesn't, am I doing something wrong?

Codes

class MySQLiteTool(private val library: Path) {
    val connection: Connection by lazy {
        Class.forName("org.sqlite.JDBC")
        DriverManager.getConnection("jdbc:sqlite:$library")
    }
...
dependencies {
    implementation("org.xerial:sqlite-jdbc:3.39.3.0")
}

Logs

Failed to load native library:jansi-2.4.0-2db311a958a8e929-libjansi.so. osinfo: Linux/arm64
java.lang.UnsatisfiedLinkError: /data/data/com.termux/files/usr/tmp/jansi-2.4.0-2db311a958a8e929-libjansi.so: dlopen failed: library "libc.so.6" not found: needed by /data/data/com.termux/files/usr/tmp/jansi-2.4.0-2db311a958a8e929-libjansi.so in namespace (default)
...
...
2022-09-21 10:17:22 W/stderr: Failed to load native library:sqlite-3.36.0.3-ffd4f25b-64e0-4683-a009-8a70f7c36428-libsqlitejdbc.so. osinfo: Linux/aarch64
2022-09-21 10:17:22 W/stderr: java.lang.UnsatisfiedLinkError: /data/data/com.termux/files/usr/tmp/sqlite-3.36.0.3-ffd4f25b-64e0-4683-a009-8a70f7c36428-libsqlitejdbc.so: dlopen failed: library "libc.so.6" not found: needed by /data/data/com.termux/files/usr/tmp/sqlite-3.36.0.3-ffd4f25b-64e0-4683-a009-8a70f7c36428-libsqlitejdbc.so in namespace (default)
2022-09-21 10:17:22 E/AzurLaneLibrary: java.sql.SQLException: Error opening connection
java.sql.SQLException: Error opening connection
## Termux App Info
**APP_NAME**: `Termux`  
**PACKAGE_NAME**: `com.termux`  
**VERSION_NAME**: `0.118.0`  
**VERSION_CODE**: `118`  
**TARGET_SDK**: `28`  
## Device Info
### Hardware
**SUPPORTED_ABIS**: `arm64-v8a, armeabi-v7a, armeabi`  

AdorableParker avatar Sep 21 '22 10:09 AdorableParker

What's termux? What is the hardware you run that on?

gotson avatar Sep 21 '22 10:09 gotson

termux is this termux app I am running as a jar on an android device

AdorableParker avatar Sep 21 '22 10:09 AdorableParker

Seems like Termux reports as Linux instead of Android, and the native lib can't be loaded because of that.

To confirm this, you could try specifying the library path https://github.com/xerial/sqlite-jdbc/blob/master/USAGE.md#how-to-use-a-specific-native-library and try to load the android lib instead https://github.com/xerial/sqlite-jdbc/tree/master/src/main/resources/org/sqlite/native/Linux-Android

gotson avatar Sep 21 '22 10:09 gotson

You can also do some tests to find why this doesn't work on your system : https://github.com/xerial/sqlite-jdbc/blob/c8e86ae4eb5658b519f02971c5ffe19149bcd9d5/src/main/java/org/sqlite/util/OSInfo.java#L114

gotson avatar Sep 21 '22 10:09 gotson

ok i will try it

AdorableParker avatar Sep 21 '22 11:09 AdorableParker