Use 32-Bit Jni Libraries on 64-Bit Android

Use 32-bit jni libraries on 64-bit android

Found an explanation: 64-bit Android can use 32-bit native libraries as a fallback, only if System.loadlLibrary() can't find anything better in the default search path.
You get an UnsatisfiedLinkError if you force the system to load the 32-bit library using System.load() with the full library path.
So the first workaround is using System.loadLibrary() instead of System.load().

An additional thing that has to be taken into account is that libraries cannot be mixed: the fallback behaviour only applies for the first library your application loads. If the first one is 64-bit, no 32-bit libraries can be loaded by the same application, and vice versa.

Android JNI: 32-bit compatability with 64-bit devices?

The 32 bits libraries will work just fine on 64 bits processors.

As long as the libraries get installed the right/official way (i.e., not manually downloaded or extracted from some nonstandard part in the APK, but packaged properly in the APK), the package manager will detect that the process uses 32 bit libraries, and the process should be started in 32 bit mode. If not, the process will be started in 64 bit mode, and later will be unable to load 32 bit libraries. (If your APK would contain some .so files, but not all, in 64 bit mode, it would only install them, and the process would be launched in 64 bit mode. So unless all .so files are available for a specific ABI, don't include any of them).

So if you have a 64 bit version of one of the native libraries, just remove that and only ship the 32 bit version, until you have 64 bit versions of all of them.

How to use 32-bit native libraries on 64-bit Android device

When you install an APK on Android, the system will look for native libraries directories (armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips64, mips) inside the lib folder of the APK, in the order determined by Build.SUPPORTED_ABIS.

If your app happen to have an arm64-v8a directory with missing libs, the missing libs will not be installed from another directory, the libs aren't mixed. That means you have to provide the full set of your libraries for each architecture.

So, to solve your issue, you can remove your 64-bit libs from your build, or set abiFilters to package only 32-bit architectures:

android {
....
defaultConfig {
....
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
}

In my app included 64-bit libraries but when i analysis apk it's still 32 bit

Change your gradle to this:

    android { 
compileSdkVersion 29
defaultConfig {
applicationId "com.panache.fm"
minSdkVersion 16
targetSdkVersion 29
versionCode 4
versionName "1.3"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

manifestPlaceholders = [onesignal_app_id : "77d104e0-6665-4288-a324-b74296fe24d4",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "REMOTE"]

}

splits {
abi{
enable true
reset()
include 'x86_64','x86','armeabi','armeabi-v7a','arm64-v8a'
universalApk true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Update

It seams that this two configuration can't be set together. So you have two options:

  1. Disable splitting APK (you've figured it out already). Than you will have one APK.
  2. Remove ndk.abiFilters setting. Than you will have multiple (probably much smaller) APKs. Moreover, with universalApk true, an universal APK with all architectures will be generated (probably much larger than in option 1).


Related Topics



Leave a reply



Submit