Generating Multiple Apk according to the Native ABI

给你一囗甜甜゛ 提交于 2019-12-24 08:03:17

问题


I am building release apk based on the ABI because of apk size to publish on Play store.

So I started apk building for ABI = armeabi-v7a then building ABI = x86 and ABI = areambi

so my gradle look like this

app gradle

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.package"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
    splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true
            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.

            // Resets the list of ABIs that Gradle should create APKs for to none.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "armeabi-v7a"

            // Specifies that we do not want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }
}

So my question

  1. I need to make changes in versionCode 1 for each ABI, so which version code for which ABI should I use.

回答1:


I have to make 2 different build

Build 1: for armeabi-v7a

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

Build 2 : for x86

versionCode 61614001
splits {
    abi {
        enable true
        reset()
        include "x86"
        universalApk false
    }
}

Added native library accordingly to the abi supported.

After that published the apk Build 1 and Build 2 together will show you the supported devices.




回答2:


productFlavors{  

    arm{  
        ndk{  
            abiFilters "arm64-v8a" , "armeabi"  , "armeabi-v7a"  
        }  
    }  
    x86{  
        ndk{  
            abiFilters "x86" , "x86_64"  
        }  
    }  
}  


来源:https://stackoverflow.com/questions/47302063/generating-multiple-apk-according-to-the-native-abi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!