I am using Android Studio 2.1 with NDK. But I am facing issues about how to configure for versionCode
. From this androidbycode blog link and this answer from Stackoverflow I tried to edit my original bulid.gradle, but it shows error on syncing.
Build.gradle (it's working fine, when there is no version merging)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.mytestapp"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 101
versionName "1.0.1"
}
buildTypes {
release {
minifyEnabled true
proguardFiles.add(file("proguard-rules.pro"))
signingConfig = $("android.signingConfigs.myConfig")
}
debug {
debuggable true
}
}
productFlavors {
create("armeabi") {
ndk {
abiFilters.add("armeabi")
versionCode 1
}
}
create("armeabi-v7a") {
ndk {
abiFilters.add("armeabi-v7a")
versionCode 3
}
}
create("x86") {
ndk {
abiFilters.add("x86")
versionCode 6
}
}
create("fat") {
ndk {
abiFilters.add("armeabi")
abiFilters.add("armeabi-v7a")
abiFilters.add("x86")
versionCode 0
}
}
}
}
// You can modify the NDK configuration for each variant.
components.android {
binaries.afterEach { binary ->
binary.mergedNdkConfig.cppFlags.add(
"-DVARIANT=\"" + binary.name + "\"")
}
}
android.signingConfigs {
create("myConfig") {
storeFile "MyKeyStoreLocation"
storePassword "MyStorePassword"
keyAlias "mykeyAlias"
keyPassword "mykeyPassword"
storeType "jks"
}
}
android.ndk {
moduleName = "settings-jni"
}
}
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/lukaville/maven"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'net.zetetic:android-database-sqlcipher:3.4.0@aar'
compile 'com.nbsp:library:1.08'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.mcxiaoke.volley:library:1.+'
compile 'com.daimajia.numberprogressbar:library:1.2@aar'
compile 'com.github.paolorotolo:appintro:3.4.0'
}
I couldn't find a way to merge the code snippet for ABI versioning, as suggested in above mentioned SO answer
applicationVariants.all { variant ->
// get the version code of each flavor
def abiVersion = variant.productFlavors.get(0).versionCode
// set the composite code
variant.mergedFlavor.versionCode = abiVersion * 100000 + defaultConfig.versionCode
}
Or, as suggested in above mentioned blog link, with my build.gradle
-
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(
com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode
}
}