storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.15k stars 716 forks source link

Support 16 KB page sizes #1021

Open xavierserrai opened 4 months ago

xavierserrai commented 4 months ago

Dears,

Beginning with Android 15, Android supports devices that are configured to use a page size of 16 KB (16 KB devices).

https://developer.android.com/guide/practices/page-sizes#other-build-systems

I have tested this plugin with an Android 15 emulator that uses 16KB page sizes and when creating a database app crashes giving the following error:

FATAL EXCEPTION: pool-10-thread-3
Process: <PROCESS NAME>, PID: 12109
java.lang.UnsatisfiedLinkError: dlopen failed: empty/missing DT_HASH/DT_GNU_HASH in "/data/app/~~f4HklBgA8FB4x-ytaY2XqA==/<APP NAME>-ltZeoe99ImEJ3PBAJKzLow==/base.apk!/lib/arm64-v8a/libsqlc-ndk-native-driver.so" (new hash type from the future?)
at java.lang.Runtime.loadLibrary0(Runtime.java:1081)
at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
at java.lang.System.loadLibrary(System.java:1765)
at io.liteglue.SQLiteConnector.<init>(SQLiteConnector.java:8)
at io.sqlc.SQLiteConnectorDatabase.<clinit>(SQLiteConnectorDatabase.java:35)
at io.sqlc.SQLitePlugin.openDatabase(SQLitePlugin.java:212)
at io.sqlc.SQLitePlugin.access$000(SQLitePlugin.java:28)
at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:328)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)

libsqlc-ndk-native-driver.so might need to be recompiled to support 16KB page sizes.

Thanks,

hooliapps commented 4 months ago

Hello

I have the same demand.

I use the plugin in my major apps: cordova-sqlite-ext

I also use the following plugin on other app: cordova-sqlite-legacy-build-support

Hello, for info I did a small analysis of the concerned libraries.

  1. Plugin cordova-sqlite-legacy-build-support 1.3.5 Library in analysed APK: lib/arm64-v8a/libsqlc-native-driver.so Dependencies in plugin.xml:

    <source-file src="src/android/libs/sqlite-connector.jar" target-dir="libs"/>
    <!-- Android-sqlite-connector native driver [native libs]: -->
    <source-file src="src/android/libs/arm64-v8a/libsqlc-native-driver.so" target-dir="libs/arm64-v8a"/>
    <source-file src="src/android/libs/armeabi/libsqlc-native-driver.so" target-dir="libs/armeabi"/>
    <source-file src="src/android/libs/armeabi-v7a/libsqlc-native-driver.so" target-dir="libs/armeabi-v7a"/>
    <source-file src="src/android/libs/x86/libsqlc-native-driver.so" target-dir="libs/x86"/>
    <source-file src="src/android/libs/x86_64/libsqlc-native-driver.so" target-dir="libs/x86_64"/>
  2. Plugin cordova-sqlite-ext 6.0.0 Library in analysed APK: lib/arm64-v8a/libsqlc-ndk-native.driver.so Dependencies in package.json: "dependencies": { "cordova-sqlite-ext-deps": "4.0.0" }

    In Plugin cordova-sqlite-ext-deps
    libs/
        sqlite-native-ndk-connector.jar
        sqlite-ndk-native-driver.jar
    Documentation:
        sqlite3.h, sqlite3.c - SQLite 3.32.3 amalgamation needed to build iOS/macOS and Windows platform versions
        libb64-core, sqlite3-base64, and sqlite3-regexp-cached source for iOS/macOS/Windows platform versions
        libs - JAR libraries built from brodybits/android-sqlite-ndk-native-driver and brodybits/android-sqlite-native-ndk-connector, built with SQLite 3.32.3 amalgamation
xavierserrai commented 3 months ago

Any updates on this?

@brodycj

hooliapps commented 3 months ago

Hello

Here some infos/hints to help to correct the problem.

I found this depot who seems to generate the .so libs https://github.com/brodycj/Android-sqlite-ext-native-driver/blob/master/jni/Android.mk

Some doc: https://developer.android.com/guide/practices/page-sizes "If your app uses any native code, then you should rebuild your app with support for 16 KB devices."

With NDK 26 at minimum, it seems one of the following flags must be added: ndk-build: LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384" CMake: target_link_options(${CMAKE_PROJECT_NAME} PRIVATE "-Wl,-z,max-page-size=16384")

hooliapps commented 3 months ago

Additional infos, i recompiled the Libs (thanks to Norman B.).

Libs are not tested currently.

"I followed your exemple, i did not "make init", but i executed ndk-build. Libs are created, 4 systems just armeabi is missing, i analysed the ELF files, there are some differences with your build (I used NDK 26.1) but i see 0x4000 :clin_d'œil: I will do some tests with the New Libs.

Sans titre
hooliapps commented 3 months ago

Hello, tested with Pixel 8 With Android 15 QR1 + Page Size 16Kb Mode.

App don't works and are not downloadable from Google Play also.

hooliapps commented 3 months ago

Logs from google play store: did a adb log, and seems related... 08-24 19:59:25.598 3358 3358 E Finsky : [2] tpg.d(22): Submitter: commit error message INSTALL_FAILED_INVALID_APK: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2

20 h 02 08-24 19:59:25.584 1350 1692 E NativeLibraryHelper: Library 'libsqlc-ndk-native-driver.so' is not PAGE(16384)-aligned - will not be able to open it directly from apk.

NityaSantosh26 commented 2 months ago

I cloned https://github.com/brodycj/android-sqlite-ndk-native-driver and made changes to Application.mk as specified in Android documentation: https://developer.android.com/guide/practices/page-sizes#compile-r27-higher Used ndk 27 and build the repository and using "make", Executed "make Makefile" which generated the jar file from the .so files. Replaced the jar that this plugin uses from cordova-sqlite-storage-dependencies and built the app. App launches in Android 15 Emulator. Verified sqlite db functionality and it works.

Raised a PR on https://github.com/brodycj/android-sqlite-ndk-native-driver/pull/10 Waiting for the author @brodycj to re-build the project.

hooliapps commented 2 months ago

Thanks for your commit.

I advice you also test on real AAB Bu dle on Google Play. Because i had the following problem, recompilation seems not enough.

If not works, you will need to do that on your Main app.

In your Cordova app, you must add the following code in /app/build.gradle, under android { block: packagingOptions { jniLibs { useLegacyPackaging = true } }

NityaSantosh26 commented 2 months ago

@hooliapps, Thanks for the suggestion. You're correct, I couldn't install the app from play store (Bundle AAB). Adding the line provided in app/build.gradle fixed the installation. This means AGP version also needs to be updated to 8.5 or above as mentioned in Android documentation? https://developer.android.com/guide/practices/page-sizes#update-packaging

NityaSantosh26 commented 1 month ago

@brodycj , Any update?