forked from anonvector/SlipNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
454 lines (390 loc) · 15.4 KB
/
build.gradle.kts
File metadata and controls
454 lines (390 loc) · 15.4 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.net.URL
import java.io.FileOutputStream
import java.util.zip.ZipInputStream
import java.util.Properties
plugins {
id("com.android.application")
id("org.mozilla.rust-android-gradle.rust-android")
kotlin("android")
kotlin("kapt")
id("org.jetbrains.kotlin.plugin.compose")
id("com.google.dagger.hilt.android")
}
val minSdkVersion = 24
val appVersionName = "1.7.6"
val appVersionCode = 19
val cargoProfile = (findProperty("CARGO_PROFILE") as String?) ?: run {
val isRelease = gradle.startParameter.taskNames.any { it.contains("Release", ignoreCase = true) }
if (isRelease) "release" else "debug"
}
fun abiFromTarget(target: String): String = when {
target.startsWith("aarch64") -> "arm64-v8a"
target.startsWith("armv7") || target.startsWith("arm") -> "armeabi-v7a"
target.startsWith("i686") -> "x86"
target.startsWith("x86_64") -> "x86_64"
else -> target
}
// Signing configuration
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(keystorePropertiesFile.inputStream())
}
// OpenSSL configuration
val opensslVersion = "3.0.15"
val opensslBaseDir = file("${System.getenv("HOME")}/android-openssl/android-ssl")
val supportedAbis = listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
// Check if OpenSSL is available for all ABIs
fun isOpenSslAvailable(): Boolean {
return supportedAbis.all { abi ->
val libDir = opensslBaseDir.resolve("$abi/lib")
val includeDir = opensslBaseDir.resolve("$abi/include")
libDir.resolve("libssl.a").exists() &&
libDir.resolve("libcrypto.a").exists() &&
includeDir.exists()
}
}
android {
val javaVersion = JavaVersion.VERSION_17
namespace = "app.slipnet"
compileSdk = 36
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
signingConfigs {
create("release") {
if (keystorePropertiesFile.exists()) {
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["storePassword"] as String
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["keyPassword"] as String
}
}
}
defaultConfig {
applicationId = "app.slipnet"
minSdk = minSdkVersion
targetSdk = 35
versionCode = appVersionCode
versionName = appVersionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isShrinkResources = true
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("release")
}
}
buildFeatures {
compose = true
buildConfig = true
}
applicationVariants.all {
outputs.all {
val output = this as com.android.build.gradle.internal.api.BaseVariantOutputImpl
val abiFilter = output.getFilter("ABI")
val abi = abiFilter ?: "universal"
val newName = "SlipNet-v${appVersionName}-${buildType.name}-${abi}.apk"
output.outputFileName = newName
}
}
splits {
abi {
isEnable = true
reset()
include("arm64-v8a", "armeabi-v7a")
isUniversalApk = true
}
}
ndkVersion = "29.0.14206865"
packaging {
jniLibs {
useLegacyPackaging = true
}
}
// Build hev-socks5-tunnel with ndk-build
externalNativeBuild {
ndkBuild {
path = file("src/main/cpp/Android.mk")
}
}
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
val cargoHome = System.getenv("HOME") + "/.cargo"
val cargoBin = "$cargoHome/bin"
// Task to setup OpenSSL for Android
tasks.register("setupOpenSsl") {
group = "build setup"
description = "Downloads and sets up OpenSSL for Android if not present"
doLast {
if (isOpenSslAvailable()) {
println("OpenSSL for Android is already available at: $opensslBaseDir")
return@doLast
}
println("OpenSSL for Android not found. Setting up...")
val downloadUrl = "https://github.com/passy/build-openssl-android/releases/download/v${opensslVersion}/openssl-${opensslVersion}-android.zip"
val tempZip = file("${buildDir}/tmp/openssl-android.zip")
val extractDir = file("${buildDir}/tmp/openssl-extract")
// Create directories
tempZip.parentFile.mkdirs()
extractDir.mkdirs()
opensslBaseDir.mkdirs()
println("Downloading OpenSSL from: $downloadUrl")
try {
// Try primary download source
downloadFile(downloadUrl, tempZip)
} catch (e: Exception) {
println("Primary download failed, trying alternative source...")
// Alternative: build from source using script
val buildScript = file("$projectDir/scripts/build-openssl-android.sh")
if (buildScript.exists()) {
exec {
commandLine("bash", buildScript.absolutePath)
environment("OPENSSL_VERSION", opensslVersion)
environment("OUTPUT_DIR", opensslBaseDir.absolutePath)
environment("ANDROID_NDK_HOME", android.ndkDirectory.absolutePath)
}
return@doLast
} else {
throw GradleException("""
Failed to download OpenSSL for Android.
Please manually set up OpenSSL:
1. Download pre-built OpenSSL for Android
2. Extract to: $opensslBaseDir
3. Ensure each ABI folder (arm64-v8a, armeabi-v7a, x86, x86_64) contains:
- lib/libssl.a
- lib/libcrypto.a
- include/openssl/
Or run: ./scripts/build-openssl-android.sh
""".trimIndent())
}
}
println("Extracting OpenSSL...")
extractZip(tempZip, extractDir)
// Copy to final location
supportedAbis.forEach { abi ->
val srcDir = extractDir.resolve(abi)
val dstDir = opensslBaseDir.resolve(abi)
if (srcDir.exists()) {
srcDir.copyRecursively(dstDir, overwrite = true)
println("Installed OpenSSL for $abi")
}
}
// Cleanup
tempZip.delete()
extractDir.deleteRecursively()
println("OpenSSL setup complete!")
}
}
fun downloadFile(url: String, destination: File) {
URL(url).openStream().use { input ->
FileOutputStream(destination).use { output ->
input.copyTo(output)
}
}
}
fun extractZip(zipFile: File, destDir: File) {
ZipInputStream(zipFile.inputStream()).use { zis ->
var entry = zis.nextEntry
while (entry != null) {
val destFile = File(destDir, entry.name)
if (entry.isDirectory) {
destFile.mkdirs()
} else {
destFile.parentFile?.mkdirs()
destFile.outputStream().use { fos ->
zis.copyTo(fos)
}
}
entry = zis.nextEntry
}
}
}
// Task to verify OpenSSL setup
tasks.register("verifyOpenSsl") {
group = "verification"
description = "Verifies that OpenSSL for Android is properly set up"
doLast {
val missing = mutableListOf<String>()
supportedAbis.forEach { abi ->
val libDir = opensslBaseDir.resolve("$abi/lib")
val includeDir = opensslBaseDir.resolve("$abi/include")
if (!libDir.resolve("libssl.a").exists()) {
missing.add("$abi/lib/libssl.a")
}
if (!libDir.resolve("libcrypto.a").exists()) {
missing.add("$abi/lib/libcrypto.a")
}
if (!includeDir.resolve("openssl").exists()) {
missing.add("$abi/include/openssl/")
}
}
if (missing.isNotEmpty()) {
throw GradleException("""
OpenSSL for Android is not properly set up.
Missing files in $opensslBaseDir:
${missing.joinToString("\n - ", prefix = " - ")}
Run './gradlew setupOpenSsl' to download and set up OpenSSL.
""".trimIndent())
}
println("OpenSSL verification passed! All required files present.")
}
}
cargo {
cargoCommand = "$cargoBin/cargo"
rustcCommand = "$cargoBin/rustc"
module = "src/main/rust/slipstream-rust"
libname = "slipstream"
targets = listOf("arm", "arm64", "x86", "x86_64")
profile = cargoProfile
rustupChannel = "stable"
extraCargoBuildArguments = listOf(
"-p", "slipstream-client",
"--lib", // Only build the library, not the binary (avoids overwriting cdylib with executable)
"--features", "openssl-static,picoquic-minimal-build",
)
exec = { spec, toolchain ->
// Add cargo to PATH
val currentPath = System.getenv("PATH") ?: ""
spec.environment("PATH", "$cargoHome/bin:$currentPath")
// Try python3 first, fall back to python
// The rust-android-gradle plugin will handle errors if python is not available
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3")
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/src/main/rust/linker-wrapper.py"
)
spec.environment(
"RUST_ANDROID_GRADLE_TARGET",
"target/${toolchain.target}/$cargoProfile/lib$libname.so"
)
val abi = abiFromTarget(toolchain.target)
spec.environment("ANDROID_NDK_HOME", android.ndkDirectory.absolutePath)
spec.environment("ANDROID_ABI", abi)
spec.environment("ANDROID_PLATFORM", "android-$minSdkVersion")
spec.environment(
"PICOQUIC_BUILD_DIR",
"$projectDir/src/main/rust/slipstream-rust/.picoquic-build/$abi"
)
spec.environment("PICOQUIC_AUTO_BUILD", "1")
spec.environment("BUILD_TYPE", if (cargoProfile == "release") "Release" else "Debug")
// Add OpenSSL paths for picoquic build and openssl-sys
val opensslAbiDir = opensslBaseDir.resolve(abi)
spec.environment("OPENSSL_DIR", opensslAbiDir.absolutePath)
spec.environment("OPENSSL_LIB_DIR", opensslAbiDir.resolve("lib").absolutePath)
spec.environment("OPENSSL_INCLUDE_DIR", opensslAbiDir.resolve("include").absolutePath)
// For picoquic build script
spec.environment("OPENSSL_ROOT_DIR", opensslAbiDir.absolutePath)
spec.environment("OPENSSL_CRYPTO_LIBRARY", opensslAbiDir.resolve("lib/libcrypto.a").absolutePath)
spec.environment("OPENSSL_SSL_LIBRARY", opensslAbiDir.resolve("lib/libssl.a").absolutePath)
spec.environment("OPENSSL_USE_STATIC_LIBS", "1")
val toolchainPrebuilt = android.ndkDirectory
.resolve("toolchains/llvm/prebuilt")
.listFiles()
?.firstOrNull { it.isDirectory }
val toolchainBin = toolchainPrebuilt?.resolve("bin")
if (toolchainBin != null) {
spec.environment("AR", toolchainBin.resolve("llvm-ar").absolutePath)
spec.environment("RANLIB", toolchainBin.resolve("llvm-ranlib").absolutePath)
}
}
}
// Make cargo build tasks depend on OpenSSL verification
tasks.whenTaskAdded {
when (name) {
"cargoBuildArm", "cargoBuildArm64", "cargoBuildX86", "cargoBuildX86_64" -> {
dependsOn("verifyOpenSsl")
}
"mergeDebugJniLibFolders", "mergeReleaseJniLibFolders" -> {
dependsOn("cargoBuild")
// Track Rust JNI output without adding a second source set (avoids duplicate resources).
inputs.dir(layout.buildDirectory.dir("rustJniLibs/android"))
}
}
}
tasks.register<Exec>("cargoClean") {
executable("$cargoBin/cargo")
args("clean")
workingDir("$projectDir/${cargo.module}")
}
tasks.named("clean") {
dependsOn("cargoClean")
}
dependencies {
// Combined Go library (DNSTT + Snowflake)
// Built via: cd gomobile-build && make build
implementation(files("libs/golibs.aar"))
// Tor binary for Snowflake tunnel — libtor.so extracted from
// info.guardianproject:tor-android:0.4.8.22 into jniLibs/
// (AAR excluded as Gradle dep because its Kotlin metadata 2.3.0
// is incompatible with Room 2.6.1 kapt processor)
// Compose BOM
val composeBom = platform("androidx.compose:compose-bom:2026.01.01")
implementation(composeBom)
androidTestImplementation(composeBom)
// Compose
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material-icons-extended")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
// Activity Compose
implementation("androidx.activity:activity-compose:1.12.4")
// Lifecycle & ViewModel
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.10.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.10.0")
// Navigation Compose
implementation("androidx.navigation:navigation-compose:2.9.7")
// Hilt
implementation("com.google.dagger:hilt-android:2.59.1")
kapt("com.google.dagger:hilt-compiler:2.59.1")
implementation("androidx.hilt:hilt-navigation-compose:1.3.0")
// Room
implementation( "androidx.room:room-runtime:2.8.4")
implementation("androidx.room:room-ktx:2.8.4")
kapt("androidx.room:room-compiler:2.8.4")
// DataStore
implementation("androidx.datastore:datastore-preferences:1.2.0")
// Kotlin Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
// JSON serialization for Room converters
implementation("com.google.code.gson:gson:2.13.2")
// SSH tunneling library (mwiede fork — supports modern ciphers: AES-GCM, ChaCha20)
implementation("com.github.mwiede:jsch:2.27.7")
// OkHttp for DoH (HTTP/2, connection pooling, custom DNS resolver)
implementation("com.squareup.okhttp3:okhttp:5.3.2")
// Drag-and-drop reorderable LazyColumn
implementation("sh.calvin.reorderable:reorderable:3.0.0")
// QR code generation & scanning
implementation("com.google.zxing:core:3.5.4")
implementation("com.journeyapps:zxing-android-embedded:4.3.0")
// Core
implementation("androidx.core:core-ktx:1.17.0")
// Testing
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test:runner:1.7.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
}
kapt {
correctErrorTypes = true
// Room schema export
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}