2021-02-28 07:08:33 +00:00
|
|
|
import cn.hutool.core.codec.Base64
|
2020-06-25 04:14:31 +00:00
|
|
|
import com.android.build.gradle.internal.tasks.factory.dependsOn
|
2021-02-28 07:08:33 +00:00
|
|
|
import org.apache.tools.ant.filters.StringInputStream
|
|
|
|
import java.util.*
|
|
|
|
import java.io.*
|
2020-06-25 04:14:31 +00:00
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("com.android.library")
|
|
|
|
id("org.mozilla.rust-android-gradle.rust-android")
|
|
|
|
}
|
|
|
|
|
2021-02-28 07:08:33 +00:00
|
|
|
var ignoreX86 = false
|
|
|
|
|
|
|
|
lateinit var properties: Properties
|
|
|
|
val base64 = System.getenv("LOCAL_PROPERTIES")
|
|
|
|
if (!base64.isNullOrBlank()) {
|
|
|
|
properties = Properties()
|
|
|
|
properties.load(ByteArrayInputStream(Base64.decode(base64)))
|
|
|
|
} else if (project.rootProject.file("local.properties").exists()) {
|
|
|
|
properties = Properties()
|
|
|
|
properties.load(StringInputStream(project.rootProject.file("local.properties").readText()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::properties.isInitialized) {
|
|
|
|
ignoreX86 = properties.getProperty("IGNORE_X86") == "true"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-25 04:14:31 +00:00
|
|
|
android {
|
|
|
|
|
2021-02-18 02:32:07 +00:00
|
|
|
ndkVersion = rootProject.extra.get("ndkVersion").toString()
|
2020-06-25 04:14:31 +00:00
|
|
|
|
2020-07-27 04:49:42 +00:00
|
|
|
compileSdkVersion(30)
|
2020-06-25 04:14:31 +00:00
|
|
|
defaultConfig {
|
2020-08-10 10:20:22 +00:00
|
|
|
minSdkVersion(21)
|
2020-07-27 04:49:42 +00:00
|
|
|
targetSdkVersion(30)
|
2020-06-25 04:14:31 +00:00
|
|
|
}
|
2020-12-16 16:36:50 +00:00
|
|
|
buildToolsVersion = "30.0.3"
|
2020-06-25 04:14:31 +00:00
|
|
|
|
2021-02-28 07:08:33 +00:00
|
|
|
if (ignoreX86) {
|
|
|
|
splits.abi {
|
|
|
|
exclude("x86", "x86_64")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cargo {
|
|
|
|
module = "src/main/rust/shadowsocks-rust"
|
|
|
|
libname = "ss-local"
|
2021-02-28 07:08:33 +00:00
|
|
|
targets = if (ignoreX86) {
|
|
|
|
listOf("arm", "arm64")
|
|
|
|
} else {
|
|
|
|
listOf("arm", "arm64", "x86", "x86_64")
|
|
|
|
}
|
2020-06-25 04:14:31 +00:00
|
|
|
profile = findProperty("CARGO_PROFILE")?.toString() ?: "release"
|
|
|
|
extraCargoBuildArguments = listOf("--bin", "sslocal")
|
|
|
|
featureSpec.noDefaultBut(arrayOf(
|
2021-01-12 03:13:37 +00:00
|
|
|
"stream-cipher",
|
|
|
|
"logging",
|
2020-12-30 03:43:34 +00:00
|
|
|
"local-flow-stat",
|
|
|
|
"local-dns"))
|
2020-06-25 04:14:31 +00:00
|
|
|
exec = { spec, toolchain ->
|
|
|
|
spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py")
|
|
|
|
spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.whenTaskAdded {
|
|
|
|
when (name) {
|
|
|
|
"mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> dependsOn("cargoBuild")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<Exec>("cargoClean") {
|
|
|
|
executable("cargo") // cargo.cargoCommand
|
|
|
|
args("clean")
|
|
|
|
workingDir("$projectDir/${cargo.module}")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.clean.dependsOn("cargoClean")
|