|
| 1 | +import org.apache.tools.ant.taskdefs.condition.Os |
| 2 | +import com.android.build.OutputFile |
| 3 | + |
| 4 | +import java.util.regex.Matcher |
| 5 | +import java.util.regex.Pattern |
| 6 | + |
| 7 | +apply plugin: 'com.android.application' |
| 8 | + |
| 9 | +apply plugin: 'kotlin-android' |
| 10 | + |
| 11 | +def getCurrentFlavor() { |
| 12 | + String task = getGradle().getStartParameter().getTaskRequests().toString() |
| 13 | + Matcher matcher = Pattern.compile("(assemble|generate)\\w*(Release|Debug)").matcher(task) |
| 14 | + if (matcher.find()) return matcher.group(2).toLowerCase() else { |
| 15 | + println "Warning: No match found for $task" |
| 16 | + return "debug" |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +android { |
| 21 | + buildToolsVersion "28.0.3" |
| 22 | + compileSdkVersion 28 |
| 23 | + defaultConfig { |
| 24 | + applicationId "com.github.shadowsocks.plugin.v2ray" |
| 25 | + minSdkVersion rootProject.minSdkVersion |
| 26 | + targetSdkVersion 28 |
| 27 | + versionCode 1000000 |
| 28 | + versionName "1.0.0" |
| 29 | + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| 30 | + } |
| 31 | + buildTypes { |
| 32 | + release { |
| 33 | + minifyEnabled true |
| 34 | + shrinkResources true |
| 35 | + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 36 | + } |
| 37 | + } |
| 38 | + splits { |
| 39 | + abi { |
| 40 | + enable true |
| 41 | + universalApk true |
| 42 | + } |
| 43 | + } |
| 44 | + sourceSets.main.jniLibs.srcDirs += new File(projectDir, "src/bin") |
| 45 | +} |
| 46 | + |
| 47 | +task goBuild(type: Exec) { |
| 48 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 49 | + println "Warning: Building on Windows is not supported" |
| 50 | + } else { |
| 51 | + executable "sh" |
| 52 | + args "-c", "src/make.bash " + minSdkVersion |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +task goClean(type: Exec) { |
| 57 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 58 | + println "Warning: Building on Windows is not supported" |
| 59 | + } else { |
| 60 | + executable "sh" |
| 61 | + args "-c", "src/clean.bash" |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +tasks.whenTaskAdded { task -> |
| 66 | + if ((task.name == 'javaPreCompileDebug' || |
| 67 | + task.name == 'javaPreCompileRelease')) { |
| 68 | + task.dependsOn(goBuild) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +dependencies { |
| 73 | + implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 74 | + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" |
| 75 | + implementation 'com.github.shadowsocks:plugin:1.0.0' |
| 76 | + testImplementation 'junit:junit:4.12' |
| 77 | + androidTestImplementation 'androidx.test:runner:1.1.1' |
| 78 | + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' |
| 79 | +} |
| 80 | + |
| 81 | +ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3, x86_64: 4] |
| 82 | +if (getCurrentFlavor() == 'release') android.applicationVariants.all { variant -> |
| 83 | + variant.outputs.each { output -> |
| 84 | + def offset = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI)) |
| 85 | + if (offset != null) output.versionCodeOverride = variant.versionCode + offset |
| 86 | + } |
| 87 | +} |
0 commit comments