|
| 1 | +import com.android.build.gradle.internal.api.ApkVariantOutputImpl |
| 2 | +import com.android.build.VariantOutput |
| 3 | +import org.apache.tools.ant.taskdefs.condition.Os |
| 4 | +import java.util.Locale |
| 5 | + |
| 6 | +plugins { |
| 7 | + id("com.android.application") |
| 8 | + kotlin("android") |
| 9 | +} |
| 10 | + |
| 11 | +val flavorRegex = "(assemble|generate)\\w*(Release|Debug)".toRegex() |
| 12 | +val currentFlavor get() = gradle.startParameter.taskRequests.toString().let { task -> |
| 13 | + flavorRegex.find(task)?.groupValues?.get(2)?.toLowerCase(Locale.ROOT) ?: "debug".also { |
| 14 | + println("Warning: No match found for $task") |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +val minSdk = 21 |
| 19 | + |
| 20 | +android { |
| 21 | + val javaVersion = JavaVersion.VERSION_1_8 |
| 22 | + compileSdkVersion(29) |
| 23 | + compileOptions { |
| 24 | + sourceCompatibility = javaVersion |
| 25 | + targetCompatibility = javaVersion |
| 26 | + } |
| 27 | + kotlinOptions.jvmTarget = javaVersion.toString() |
| 28 | + defaultConfig { |
| 29 | + applicationId = "com.github.shadowsocks.plugin.v2ray" |
| 30 | + minSdkVersion(minSdk) |
| 31 | + targetSdkVersion(29) |
| 32 | + versionCode = 1030100 |
| 33 | + versionName = "1.3.1" |
| 34 | + testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" |
| 35 | + } |
| 36 | + buildTypes { |
| 37 | + getByName("release") { |
| 38 | + isShrinkResources = true |
| 39 | + isMinifyEnabled = true |
| 40 | + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") |
| 41 | + } |
| 42 | + } |
| 43 | + splits { |
| 44 | + abi { |
| 45 | + isEnable = true |
| 46 | + isUniversalApk = true |
| 47 | + } |
| 48 | + } |
| 49 | + sourceSets.getByName("main") { |
| 50 | + jniLibs.setSrcDirs(jniLibs.srcDirs + files("$projectDir/build/go")) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +tasks.register<Exec>("goBuild") { |
| 55 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 56 | + println("Warning: Building on Windows is not supported") |
| 57 | + } else { |
| 58 | + executable("/bin/bash") |
| 59 | + args("go-build.bash", minSdk) |
| 60 | + environment("ANDROID_HOME", android.sdkDirectory) |
| 61 | + environment("ANDROID_NDK_HOME", android.ndkDirectory) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +tasks.whenTaskAdded { |
| 66 | + when (name) { |
| 67 | + "mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> dependsOn("goBuild") |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +dependencies { |
| 72 | + implementation(kotlin("stdlib-jdk8", rootProject.extra.get("kotlinVersion").toString())) |
| 73 | + implementation("androidx.preference:preference:1.1.1") |
| 74 | + implementation("com.github.shadowsocks:plugin:1.3.4") |
| 75 | + implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0") |
| 76 | + testImplementation("junit:junit:4.13") |
| 77 | + androidTestImplementation("androidx.test:runner:1.2.0") |
| 78 | + androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0") |
| 79 | +} |
| 80 | + |
| 81 | +val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4) |
| 82 | +if (currentFlavor == "release") android.applicationVariants.all { |
| 83 | + for (output in outputs) { |
| 84 | + abiCodes[(output as ApkVariantOutputImpl).getFilter(VariantOutput.ABI)]?.let { offset -> |
| 85 | + output.versionCodeOverride = versionCode + offset |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments