| 5 | import java.io.* |
| 6 |
| 7 | plugins { |
| 8 | id("com.android.library") |
| 9 | id("org.mozilla.rust-android-gradle.rust-android") |
| 10 | } |
| 11 |
| 12 | var ignoreX86 = false |
| 13 |
| 14 | lateinit var properties: Properties |
| 15 | val base64 = System.getenv("LOCAL_PROPERTIES") |
| 16 | if (!base64.isNullOrBlank()) { |
| 17 | properties = Properties() |
| 18 | properties.load(ByteArrayInputStream(Base64.decode(base64))) |
| 19 | } else if (project.rootProject.file("local.properties").exists()) { |
| 20 | properties = Properties() |
| 21 | properties.load(StringInputStream(project.rootProject.file("local.properties").readText())) |
| 22 | } |
| 23 |
| 24 | if (::properties.isInitialized) { |
| 25 | ignoreX86 = properties.getProperty("IGNORE_X86") == "true" |
| 26 | } |
| 27 |
| 28 |
| 29 | android { |
| 30 |
| 31 | ndkVersion = rootProject.extra.get("ndkVersion").toString() |
| 32 |
| 33 | compileSdkVersion(30) |
| 34 | defaultConfig { |
| 35 | minSdkVersion(21) |
| 36 | targetSdkVersion(30) |
| 37 | } |
| 38 | buildToolsVersion = "30.0.3" |
| 39 |
| 40 | if (ignoreX86) { |
| 41 | splits.abi { |
| 42 | exclude("x86", "x86_64") |
| 43 | } |
| 44 | } |
| 45 |
| 46 | } |
| 47 |
| 48 | cargo { |
| 49 | module = "src/main/rust/shadowsocks-rust" |
| 50 | libname = "ss-local" |
| 51 | targets = if (ignoreX86) { |
| 52 | listOf("arm", "arm64") |
| 53 | } else { |
| 54 | listOf("arm", "arm64", "x86", "x86_64") |
| 55 | } |
| 56 | profile = findProperty("CARGO_PROFILE")?.toString() ?: "release" |
| 57 | extraCargoBuildArguments = listOf("--bin", "sslocal") |
| 58 | featureSpec.noDefaultBut(arrayOf( |
| 59 | "stream-cipher", |
| 60 | "logging", |
| 61 | "local-flow-stat", |
| 62 | "local-dns")) |
| 63 | exec = { spec, toolchain -> |
| 64 | spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") |
| 65 | spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") |
| 66 | } |
| 67 | } |
| 68 |
| 69 | tasks.whenTaskAdded { |
| 70 | when (name) { |
| 71 | "mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> dependsOn("cargoBuild") |
| 72 | } |
| 73 | } |
| 74 |
| 75 | tasks.register<Exec>("cargoClean") { |
| 76 | executable("cargo") // cargo.cargoCommand |
| 77 | args("clean") |
| 78 | workingDir("$projectDir/${cargo.module}") |
| 79 | } |
| 80 |
| 81 | tasks.clean.dependsOn("cargoClean") |