116 lines
3.1 KiB
Plaintext
116 lines
3.1 KiB
Plaintext
import java.net.URI
|
|
import org.gradle.api.tasks.compile.JavaCompile
|
|
|
|
plugins {
|
|
id("com.android.application")
|
|
}
|
|
|
|
val releaseBaseUrl = providers.gradleProperty("WNH_BASE_URL").orElse("")
|
|
val debugBaseUrl = providers.gradleProperty("WNH_DEBUG_BASE_URL").orElse("")
|
|
|
|
android {
|
|
namespace = "org.whoneedhelp.mobile"
|
|
compileSdk = 37
|
|
buildToolsVersion = "37.0.0"
|
|
|
|
defaultConfig {
|
|
applicationId = "org.whoneedhelp.mobile"
|
|
minSdk = 24
|
|
targetSdk = 37
|
|
versionCode = 1
|
|
versionName = "0.1.0"
|
|
|
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
}
|
|
|
|
buildTypes {
|
|
debug {
|
|
applicationIdSuffix = ".debug"
|
|
versionNameSuffix = "-debug"
|
|
buildConfigField(
|
|
"String",
|
|
"BASE_URL",
|
|
"\"${debugBaseUrl.get().replace("\\", "\\\\").replace("\"", "\\\"")}\""
|
|
)
|
|
manifestPlaceholders["usesCleartextTraffic"] = "true"
|
|
}
|
|
|
|
release {
|
|
isMinifyEnabled = true
|
|
isShrinkResources = true
|
|
buildConfigField(
|
|
"String",
|
|
"BASE_URL",
|
|
"\"${releaseBaseUrl.get().replace("\\", "\\\\").replace("\"", "\\\"")}\""
|
|
)
|
|
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
|
proguardFiles(
|
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
"proguard-rules.pro"
|
|
)
|
|
}
|
|
}
|
|
|
|
buildFeatures {
|
|
buildConfig = true
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_17
|
|
targetCompatibility = JavaVersion.VERSION_17
|
|
}
|
|
|
|
testOptions {
|
|
unitTests.isIncludeAndroidResources = false
|
|
}
|
|
}
|
|
|
|
tasks.matching { it.name == "preReleaseBuild" }.configureEach {
|
|
doFirst {
|
|
val value = releaseBaseUrl.orNull.orEmpty()
|
|
val uri = runCatching { URI(value) }.getOrNull()
|
|
|
|
if (
|
|
uri == null ||
|
|
uri.scheme != "https" ||
|
|
uri.host.isNullOrBlank() ||
|
|
uri.userInfo != null ||
|
|
uri.query != null ||
|
|
uri.fragment != null
|
|
) {
|
|
throw GradleException(
|
|
"Release builds require -PWNH_BASE_URL=https://your-real-deployment.example"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.matching { it.name == "preDebugBuild" }.configureEach {
|
|
doFirst {
|
|
val value = debugBaseUrl.orNull.orEmpty()
|
|
val uri = runCatching { URI(value) }.getOrNull()
|
|
|
|
if (
|
|
uri == null ||
|
|
(uri.scheme != "http" && uri.scheme != "https") ||
|
|
uri.host.isNullOrBlank() ||
|
|
uri.userInfo != null ||
|
|
uri.query != null ||
|
|
uri.fragment != null
|
|
) {
|
|
throw GradleException(
|
|
"Debug builds require -PWNH_DEBUG_BASE_URL=http(s)://your-development-host"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.withType<JavaCompile>().configureEach {
|
|
options.compilerArgs.add("-Xlint:deprecation")
|
|
}
|
|
|
|
dependencies {
|
|
implementation("androidx.activity:activity:1.13.0")
|
|
testImplementation("junit:junit:4.13.2")
|
|
}
|