6

Im facing this problem which seems im not able to solve. Here is scenario:

Im building apk which uses gradle dependency and this dependency is architecture specific so for apk for x86 i need different dependency and for arm different as well.

I solved it with product flavors:

productFlavors {

   dev { ... }
   develx86 { ... }
   production { ... }
   productionx86 { ... }

}

So then i defined dependency like this:

develCompile 'dependency_for_arm'
develx86Compile 'dependency_for_x86'

This works good. But recently i had to add to my application an usage of renderscript. I did it in this way:

renderscriptTargetApi 22
renderscriptSupportModeEnabled true

And after this when i uploaded apk on Google Play it says it's apk is suitable with arm, x86. I don't know how this is possible. As you can think it will crash on device with different CPU (if i generated apk for arm and user will execute it on x86 app will crash).

So i decited to use ABI splits:

splits {
        abi {
            enable true
            reset()
            include 'armeabi', 'x86'
            universalApk false
        }
    }

//Ensures architecture specific APKs have a higher version code
//(otherwise an x86 build would end up using the arm build, which x86 devices can run)
ext.versionCodes = [armeabi:0, x86:1]

import com.android.build.OutputFile

android.applicationVariants.all { variant ->
    // assign different version code for each output
    variant.outputs.each { output ->
        int abiVersionCode = project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) ?: 0
        output.versionCodeOverride = android.defaultConfig.versionCode + abiVersionCode
    }

But now when i see generated apk files, my dependency which is flavor-specific is not included into apk and apk will crash when i open section which uses API from this dependency.

Do someone know how to solve this issue? Or someone know why Google Play says that apk is for both architectures when i included renderscript? (Without it it works properly but i need renderscript).

Thank you for your time. I will appreciate any help.

Simon Dorociak
  • 32,775
  • 10
  • 65
  • 104

2 Answers2

2

If you look inside your APK, under lib folder, you should see that renderscript support mode added libs for other architectures than the one you're supporting.

You can keep your earlier configuration with ABI-specific flavors. But in order to ensure that no libs for other architectures are included, try adding abiFilters to your flavors:

productFlavors {

   dev { ... ndk.abiFilters 'armeabi-v7a' }
   develx86 { ... ndk.abiFilters 'x86' }
   production { ... ndk.abiFilters 'armeabi-v7a' }
   productionx86 { ... ndk.abiFilters 'x86' }

}
ph0b
  • 13,953
  • 4
  • 39
  • 38
0

Sorry I cannot comment inline yet.

What's in the apk, especially in res/raw/ and lib/? Also, are you using gradle-plugin 2.1.0? (since you are using renderscriptTargetApi 22), have you tried Build-Tools 23.0.3?

Miao Wang
  • 1,100
  • 9
  • 12