Skip to content

Commit c1cebe5

Browse files
fdroid flavor and split abi (#4162)
1 parent e46c1ee commit c1cebe5

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

V2rayNG/app/build.gradle.kts

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ android {
2929
}
3030
}
3131

32+
val abiFilterList = (properties["ABI_FILTERS"] as? String)?.split(';')
33+
if (abiFilterList != null) {
34+
ndk {
35+
abiFilters.addAll(abiFilterList)
36+
}
37+
}
38+
3239
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3340
}
3441

@@ -42,6 +49,19 @@ android {
4249
}
4350
}
4451

52+
flavorDimensions.add("distribution")
53+
productFlavors {
54+
create("fdroid") {
55+
dimension = "distribution"
56+
versionNameSuffix = "-fdroid"
57+
buildConfigField("String", "DISTRIBUTION", "\"F-Droid\"")
58+
}
59+
create("playstore") {
60+
dimension = "distribution"
61+
buildConfigField("String", "DISTRIBUTION", "\"Play Store\"")
62+
}
63+
}
64+
4565
sourceSets {
4666
getByName("main") {
4767
jniLibs.srcDirs("libs")
@@ -60,25 +80,45 @@ android {
6080

6181
applicationVariants.all {
6282
val variant = this
63-
val versionCodes =
64-
mapOf("armeabi-v7a" to 4, "arm64-v8a" to 4, "x86" to 4, "x86_64" to 4, "universal" to 4)
65-
66-
variant.outputs
67-
.map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl }
68-
.forEach { output ->
69-
val abi = if (output.getFilter("ABI") != null)
70-
output.getFilter("ABI")
71-
else
72-
"universal"
73-
74-
output.outputFileName = "v2rayNG_${variant.versionName}_${abi}.apk"
75-
if (versionCodes.containsKey(abi)) {
76-
output.versionCodeOverride =
77-
(1000000 * versionCodes[abi]!!).plus(variant.versionCode)
78-
} else {
79-
return@forEach
83+
val isFdroid = variant.productFlavors.any { it.name == "fdroid" }
84+
if (isFdroid) {
85+
val versionCodes =
86+
mapOf("armeabi-v7a" to 2, "arm64-v8a" to 1, "x86" to 4, "x86_64" to 3, "universal" to 0
87+
)
88+
89+
variant.outputs
90+
.map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl }
91+
.forEach { output ->
92+
val abi = output.getFilter("ABI") ?: "universal"
93+
output.outputFileName = "v2rayNG_${variant.versionName}_${abi}.apk"
94+
if (versionCodes.containsKey(abi)) {
95+
output.versionCodeOverride =
96+
(100 * variant.versionCode + versionCodes[abi]!!).plus(5000000)
97+
} else {
98+
return@forEach
99+
}
80100
}
81-
}
101+
} else {
102+
val versionCodes =
103+
mapOf("armeabi-v7a" to 4, "arm64-v8a" to 4, "x86" to 4, "x86_64" to 4, "universal" to 4)
104+
105+
variant.outputs
106+
.map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl }
107+
.forEach { output ->
108+
val abi = if (output.getFilter("ABI") != null)
109+
output.getFilter("ABI")
110+
else
111+
"universal"
112+
113+
output.outputFileName = "v2rayNG_${variant.versionName}_${abi}.apk"
114+
if (versionCodes.containsKey(abi)) {
115+
output.versionCodeOverride =
116+
(1000000 * versionCodes[abi]!!).plus(variant.versionCode)
117+
} else {
118+
return@forEach
119+
}
120+
}
121+
}
82122
}
83123

84124
buildFeatures {

0 commit comments

Comments
 (0)