11@file:Suppress(" UnstableApiUsage" )
22
3+ import com.android.build.api.variant.FilterConfiguration.FilterType.ABI
34import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
45import com.github.willir.rust.CargoNdkBuildTask
56import org.jetbrains.kotlin.konan.properties.hasProperty
67import org.jetbrains.kotlin.konan.properties.propertyList
78
9+ val localProperties = gradleLocalProperties(rootDir, providers)
10+ val abiFilterList = ((localProperties[" ABI_FILTERS" ] ? : properties[" ABI_FILTERS" ]) as ? String )
11+ ?.split(' ;' )
12+ val abiCodes = mapOf (" armeabi-v7a" to 1 , " arm64-v8a" to 2 , " x86" to 3 , " x86_64" to 4 )
13+
814plugins {
915 alias(libs.plugins.androidApplication)
1016 alias(libs.plugins.jetbrainsKotlinAndroid)
@@ -29,7 +35,9 @@ android {
2935 }
3036
3137 ndk {
32- abiFilters.addAll(listOf (" arm64-v8a" , " armeabi-v7a" , " x86_64" , " x86" ))
38+ if (abiFilterList == null ) {
39+ abiFilters.addAll(listOf (" armeabi-v7a" , " arm64-v8a" , " x86" , " x86_64" ))
40+ }
3341 }
3442 }
3543
@@ -87,10 +95,24 @@ android {
8795 reset()
8896
8997 // Specifies a list of ABIs that Gradle should create APKs for.
90- include(" arm64-v8a" , " armeabi-v7a" , " x86_64" , " x86" )
98+ if (abiFilterList != null && abiFilterList.isNotEmpty()) {
99+ include(* abiFilterList.toTypedArray())
100+ } else {
101+ include(" armeabi-v7a" , " arm64-v8a" , " x86" , " x86_64" )
102+
103+ // Specifies that we also want to generate a universal APK that includes all ABIs.
104+ isUniversalApk = true
105+ }
106+ }
107+ }
108+ }
91109
92- // Specifies that we also want to generate a universal APK that includes all ABIs.
93- isUniversalApk = true
110+ androidComponents {
111+ onVariants { variant ->
112+ variant.outputs.forEach { output ->
113+ val name = output.filters.find { it.filterType == ABI }?.identifier
114+ val abiCode = abiCodes[name] ? : 0
115+ output.versionCode.set(output.versionCode.get() * 10 + abiCode)
94116 }
95117 }
96118}
@@ -136,8 +158,6 @@ cargoNdk {
136158 apiLevel = 26
137159 buildType = " release"
138160
139- val localProperties = gradleLocalProperties(rootDir, providers)
140-
141161 if (localProperties.hasProperty(" ndkTargets" )) {
142162 targets = ArrayList (localProperties.propertyList(" ndkTargets" ))
143163 }
0 commit comments