Willena / sqlite-jdbc-crypt

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

`NoSuchMethodError` for Android API 23 and below #89

Closed 05nelsonm closed 1 year ago

05nelsonm commented 1 year ago

Describe the bug Android API 23 and below throws an exception because SQLiteConfig.applyRemainingPragmas function utilizes stream() which is not available.

To Reproduce

  1. Extract binaries to jniLibs directory
  2. Call JDBC.isValidUrl(null) // Android API 23 and below does not automatically load services, so need to proc registration by referencing JDBC
  3. Try to connect
  4. See error

Expected behavior Exception should not be thrown

Logs

Caused by: java.lang.NoSuchMethodError: No interface method stream()Ljava/util/stream/Stream; in class Ljava/util/Set; or its super classes (declaration of 'java.util.Set' appears in /system/framework/core-libart.jar)
at org.sqlite.SQLiteConfig.applyRemainingPragmas(SQLiteConfig.java:242)
at org.sqlite.mc.SQLiteMCConfig.setupConnection(SQLiteMCConfig.java:112)
at org.sqlite.SQLiteConfig.apply(SQLiteConfig.java:194)
at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:73)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
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:179)

Environment (please complete the following information):

Chris-SP365 commented 1 year ago

Hi,

thank you for your report. I fixed a PR for this. @Willena will you have a look?

akwizgran commented 1 year ago

It's maybe worth mentioning that there are other calls in the codebase that will cause crashes on older Android devices, such as a call to Arrays.stream() in this same file, and a call to ConcurrentHashMap.newKeySet() in DB.java. Older Android devices only have the Java 6 standard library.

These issues can be resolved without changes to sqlite-jdbc-crypt by enabling library desugaring. desugar_jdk_libs needs to be at least version 2 to support ConcurrentHashMap.newKeySet().

05nelsonm commented 1 year ago

Minimum SDK support is API 23. See >> https://github.com/xerial/sqlite-jdbc/issues/961

ConcurrentHashMap.newKeySet() called in DB.java runs fine using xerial/sqlite-jdbc, so that's a non-issue (unless my issue ticket is re-opened with support for APIs less than 23 :crossed_fingers: ), but that'd need to be fixed upstream.

Arrays.stream() might also be a problem, unsure though. Can definitely test out a -SNAPSHOT version if you'd like @Willena

Willena commented 1 year ago

@05nelsonm unfortunately I won't be able to provide you a snapshot version in the next week or two. But you should be able to easily build a snapshot yourself taking the last released sqlite binaries (available as a zip in the release page).