|
| 1 | +import com.android.build.gradle.internal.api.ApkVariantOutputImpl |
| 2 | +import java.io.FileInputStream |
| 3 | +import java.util.* |
| 4 | + |
| 5 | +plugins { |
| 6 | + alias(libs.plugins.kotlin.android) |
| 7 | + alias(libs.plugins.kotlin.serialization) |
| 8 | + alias(libs.plugins.android.application) |
| 9 | +} |
| 10 | + |
| 11 | +kotlin { jvmToolchain(21) } |
| 12 | + |
| 13 | +val orbotBaseVersionCode = 1750300200 |
| 14 | +fun getVersionName(): String { |
| 15 | + // Gets the version name from the latest Git tag |
| 16 | + return providers.exec { |
| 17 | + commandLine("git", "describe", "--tags", "--always") |
| 18 | + }.standardOutput.asText.get().trim() |
| 19 | +} |
| 20 | + |
| 21 | +android { |
| 22 | + namespace = "org.torproject.android" |
| 23 | + compileSdk = 36 |
| 24 | + |
| 25 | + defaultConfig { |
| 26 | + applicationId = namespace |
| 27 | + versionCode = orbotBaseVersionCode |
| 28 | + versionName = getVersionName() |
| 29 | + minSdk = 24 |
| 30 | + targetSdk = 36 |
| 31 | + multiDexEnabled = true |
| 32 | + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
| 33 | + flavorDimensions += "free" |
| 34 | + } |
| 35 | + |
| 36 | + compileOptions { |
| 37 | + sourceCompatibility = JavaVersion.VERSION_21 |
| 38 | + targetCompatibility = JavaVersion.VERSION_21 |
| 39 | + } |
| 40 | + |
| 41 | + splits { |
| 42 | + abi { |
| 43 | + isEnable = true |
| 44 | + reset() |
| 45 | + include("x86", "armeabi-v7a", "x86_64", "arm64-v8a") |
| 46 | + isUniversalApk = true |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + buildFeatures { |
| 51 | + buildConfig = true |
| 52 | + viewBinding = true |
| 53 | + } |
| 54 | + |
| 55 | + testOptions { execution = "ANDROIDX_TEST_ORCHESTRATOR" } |
| 56 | + |
| 57 | + signingConfigs { |
| 58 | + create("release") { |
| 59 | + val keystorePropertiesFile = rootProject.file("keystore.properties") |
| 60 | + val keystoreProperties = Properties() |
| 61 | + if (keystorePropertiesFile.canRead()) { |
| 62 | + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) |
| 63 | + } |
| 64 | + if (!keystoreProperties.stringPropertyNames().isEmpty()) { |
| 65 | + keyAlias = keystoreProperties["keyAlias"] as String |
| 66 | + keyPassword = keystoreProperties["keyPassword"] as String |
| 67 | + storeFile = file(keystoreProperties["storeFile"] as String) |
| 68 | + storePassword = keystoreProperties["storePassword"] as String |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + buildTypes { |
| 74 | + getByName("release") { |
| 75 | + isShrinkResources = false |
| 76 | + isMinifyEnabled = false |
| 77 | + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.txt") |
| 78 | + signingConfig = signingConfigs.getByName("release") |
| 79 | + } |
| 80 | + getByName("debug") { |
| 81 | + isDebuggable = true |
| 82 | + applicationIdSuffix = ".debug" |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + productFlavors { |
| 87 | + create("fullperm") { dimension = "free" } |
| 88 | + create("nightly") { |
| 89 | + dimension = "free" |
| 90 | + // overwrites defaults from defaultConfig |
| 91 | + applicationId = "org.torproject.android.nightly" |
| 92 | + versionCode = (Date().time / 1000).toInt() |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + packaging { |
| 97 | + resources { |
| 98 | + excludes += listOf("META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version") |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + lint { |
| 103 | + abortOnError = false |
| 104 | + checkReleaseBuilds = false |
| 105 | + disable += "InvalidPackage" |
| 106 | + htmlReport = true |
| 107 | + lintConfig = file("../lint.xml") |
| 108 | + textReport = false |
| 109 | + xmlReport = false |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +// Increments versionCode by ABI type |
| 114 | +android.applicationVariants.all { |
| 115 | + outputs.configureEach { -> |
| 116 | + if (versionCode == orbotBaseVersionCode) { |
| 117 | + val incrementMap = |
| 118 | + mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 4, "x86_64" to 5) |
| 119 | + val increment = incrementMap[filters.find { it.filterType == "ABI" }?.identifier] ?: 0 |
| 120 | + (this as ApkVariantOutputImpl).versionCodeOverride = orbotBaseVersionCode + increment |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +dependencies { |
| 126 | + implementation(project(":OrbotLib")) |
| 127 | + implementation(project(":orbotservice")) |
| 128 | + implementation(libs.android.material) |
| 129 | + implementation(libs.android.volley) |
| 130 | + implementation(libs.androidx.activity) |
| 131 | + implementation(libs.androidx.core.ktx) |
| 132 | + implementation(libs.androidx.localbroadcast) |
| 133 | + implementation(libs.androidx.navigation.fragment.ktx) |
| 134 | + implementation(libs.androidx.navigation.ui.ktx) |
| 135 | + implementation(libs.androidx.preference) |
| 136 | + implementation(libs.androidx.appcompat) |
| 137 | + implementation(libs.androidx.biometric) |
| 138 | + implementation(libs.androidx.lifecycle.common) |
| 139 | + implementation(libs.androidx.lifecycle.process) |
| 140 | + implementation(libs.retrofit.converter) |
| 141 | + implementation(libs.retrofit.lib) |
| 142 | + implementation(libs.rootbeer.lib) |
| 143 | + implementation(libs.kotlinx.coroutines.core) |
| 144 | + implementation(libs.kotlinx.serialization.json) |
| 145 | + implementation(libs.appiconnamechanger) |
| 146 | + |
| 147 | + testImplementation(libs.junit.jupiter) |
| 148 | + androidTestImplementation(libs.androidx.junit) |
| 149 | + androidTestImplementation(libs.androidx.espresso) |
| 150 | + androidTestImplementation(libs.androidx.rules) |
| 151 | + androidTestImplementation(libs.androidx.runner) |
| 152 | + androidTestImplementation(libs.screengrab) |
| 153 | + androidTestUtil(libs.androidx.orchestrator) |
| 154 | +} |
| 155 | + |
| 156 | +tasks.named("preBuild") { dependsOn("copyLicenseToAssets") } |
| 157 | +tasks.register<Copy>("copyLicenseToAssets") { |
| 158 | + from(layout.projectDirectory.file("LICENSE")) |
| 159 | + into(layout.projectDirectory.dir("src/main/assets")) |
| 160 | +} |
| 161 | + |
0 commit comments