import com.android.build.gradle.internal.api.ApkVariantOutputImpl import com.android.build.VariantOutput import org.apache.tools.ant.taskdefs.condition.Os import java.util.Locale plugins { id("com.android.application") kotlin("android") } val flavorRegex = "(assemble|generate)\\w*(Release|Debug)".toRegex() val currentFlavor get() = gradle.startParameter.taskRequests.toString().let { task -> flavorRegex.find(task)?.groupValues?.get(2)?.toLowerCase(Locale.ROOT) ?: "debug".also { println("Warning: No match found for $task") } } android { val javaVersion = JavaVersion.VERSION_1_8 compileSdkVersion(30) compileOptions { sourceCompatibility = javaVersion targetCompatibility = javaVersion } kotlinOptions.jvmTarget = javaVersion.toString() defaultConfig { applicationId = "com.github.shadowsocks.plugin.v2ray" minSdkVersion(23) targetSdkVersion(30) versionCode = 5009000 versionName = "5.9.0" testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } buildTypes { getByName("release") { isShrinkResources = true isMinifyEnabled = true proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") } } splits { abi { isEnable = true isUniversalApk = true } } sourceSets.getByName("main") { jniLibs.setSrcDirs(jniLibs.srcDirs + files("$projectDir/build/go")) } } tasks.register("goBuild") { if (Os.isFamily(Os.FAMILY_WINDOWS)) { println("Warning: Building on Windows is not supported") } else { executable("/bin/bash") args("go-build.bash", 23) environment("ANDROID_HOME", android.sdkDirectory) environment("ANDROID_NDK_HOME", android.ndkDirectory) } } tasks.whenTaskAdded { when (name) { "mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> dependsOn("goBuild") } } dependencies { implementation(kotlin("stdlib-jdk8", rootProject.extra.get("kotlinVersion").toString())) implementation("androidx.preference:preference:1.1.1") implementation("com.github.shadowsocks:plugin:2.0.1") implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test:runner:1.3.0") androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0") } val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4) if (currentFlavor == "release") android.applicationVariants.all { for (output in outputs) { abiCodes[(output as ApkVariantOutputImpl).getFilter(VariantOutput.ABI)]?.let { offset -> output.versionCodeOverride = versionCode + offset } } }