-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
/
build.gradle.kts
115 lines (100 loc) · 4.12 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import com.android.build.gradle.internal.tasks.factory.dependsOn
plugins {
id("com.android.library")
id("com.google.devtools.ksp")
id("org.mozilla.rust-android-gradle.rust-android")
kotlin("android")
id("kotlin-parcelize")
}
setupCore()
android {
namespace = "com.github.shadowsocks.core"
defaultConfig {
consumerProguardFiles("proguard-rules.pro")
externalNativeBuild.ndkBuild {
abiFilters("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
arguments("-j${Runtime.getRuntime().availableProcessors()}")
}
ksp {
arg("room.incremental", "true")
arg("room.schemaLocation", "$projectDir/schemas")
}
}
externalNativeBuild.ndkBuild.path("src/main/jni/Android.mk")
sourceSets.getByName("androidTest") {
assets.setSrcDirs(assets.srcDirs + files("$projectDir/schemas"))
}
buildFeatures.aidl = true
}
cargo {
module = "src/main/rust/shadowsocks-rust"
libname = "sslocal"
targets = listOf("arm", "arm64", "x86", "x86_64")
profile = findProperty("CARGO_PROFILE")?.toString() ?: currentFlavor
extraCargoBuildArguments = listOf("--bin", libname!!)
featureSpec.noDefaultBut(arrayOf(
"stream-cipher",
"aead-cipher-extra",
"logging",
"local-flow-stat",
"local-dns",
"aead-cipher-2022",
))
exec = { spec, toolchain ->
run {
try {
Runtime.getRuntime().exec(arrayOf("python3", "-V"))
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3")
project.logger.lifecycle("Python 3 detected.")
} catch (e: java.io.IOException) {
project.logger.lifecycle("No python 3 detected.")
try {
Runtime.getRuntime().exec(arrayOf("python", "-V"))
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python")
project.logger.lifecycle("Python detected.")
} catch (e: java.io.IOException) {
throw GradleException("No any python version detected. You should install the python first to compile project.")
}
}
// https://developer.android.com/guide/practices/page-sizes#other-build-systems
spec.environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,-z,max-page-size=16384,-soname,lib$libname.so")
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")
dependencies {
val coroutinesVersion = "1.9.0"
val roomVersion = "2.6.1"
val workVersion = "2.10.0"
api(project(":plugin"))
api("androidx.core:core-ktx:1.15.0")
api("com.google.android.material:material:1.12.0")
api("androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion")
api("androidx.preference:preference:1.2.1")
api("androidx.room:room-runtime:$roomVersion")
api("androidx.work:work-multiprocess:$workVersion")
api("androidx.work:work-runtime-ktx:$workVersion")
api("com.google.android.gms:play-services-oss-licenses:17.1.0")
api("com.google.code.gson:gson:2.11.0")
api("com.google.firebase:firebase-analytics:22.1.2")
api("com.google.firebase:firebase-crashlytics:19.2.1")
api("com.jakewharton.timber:timber:5.0.1")
api("dnsjava:dnsjava:3.6.2")
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
api("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion")
ksp("androidx.room:room-compiler:$roomVersion")
androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
}