Gradle android build for different processor architectures

前端 未结 4 1310
孤街浪徒
孤街浪徒 2020-12-01 03:53

I want to build 4 separate apks for 4 different Android CPU processor architectures (armeabi armeabi-v7a x86 mips) using Gradle.

I have native OpenCV libraries buil

4条回答
  •  眼角桃花
    2020-12-01 04:21

    As of Android Gradle Plugin version 13 you can now generate seperate APK's using the new "split" mechanism. You can read about it here.

    The default file structure for placing your .so files is:

    src
    -main
      -jniLibs
        -armeabi
          -arm.so
        -armeabi-v7a
          -armv7.so
        -x86
          -x86.so
        -mips
          -mips.so
    

    Note that the name of the .so file is unimportant as long as it has the .so extension.

    Then in your Gradle build file:

    android {
    ...
    splits {
    abi {
      enable true
      reset()
      include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
      universalApk false
      }
     }
    }
    

    and

    // map for the version code
    ext.versionCodes = ['armeabi-v7a':1, mips:2, x86:3]
    
    import com.android.build.OutputFile
    
    android.applicationVariants.all { variant ->
        // assign different version code for each output
        variant.outputs.each { output ->
            output.versionCodeOverride =
                project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000000 + android.defaultConfig.versionCode
        }
    }
    

    Note that the version codes above in ext.versionCodes are largely irrelevant, this is here to add a unique offset for each ABI type so version codes do not clash.

提交回复
热议问题