Search code examples
androidandroid-ndkjava-native-interfacerenderscript

RenderScript includes native binaries for all the platforms


Our Android project includes some native libraries and we support only arbeabi-v7. So the generate apk only includes native libraries for this architecture.

Lately we added RenderScript that causes the generated apk to include librsjni.so and libRSSuport.so native for all the supported platform i.e. x86, arbeabi-v7 etc.

The build.gradle files changes to add RenderScript are:

defaultConfig {
    // Other configs

    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true

}

The generated apk libs folder looks like:

libs
 - armeabi-v7
     - librsjni.so
     - libRSSuport.so
     - Other native libs
 - x86
     - librsjni.so
     - libRSSuport.so
 - Other archs
     - librsjni.so
     - libRSSuport.so

This causes issues in phones where primary abi is non armeabi-v7 as the run time may think that non armeabi-v7 architecture are supported and tries to run it and app crashes.

As of now we have added the following to build.gradle :

ndk {
    abiFilters "armeabi-v7a"
}

and in gradle.properties:

android.useDeprecatedNdk=true

Though this solves the issue, but it does seems like a hack or non standard solution.

Is there a standard or recommended way to solve this issue?


Solution

  • If you only use prebuilt libraries, your best option is to employ the splits feature:

    android {
      …
      splits { 
        abi {
          enable true
          reset()
          include "armeabi-v7a"
          universalApk false
        }
      }
    }