diff --git a/README.md b/README.md index 5cc436f23..03757eca7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,15 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta) sdk.dir=/path/to/android-sdk ``` -4. Create `signing.properties` in project root with +4. (Optional) Custom app package name. Add the following configuration to `local.properties`. + + ```properties + # config your ownn applicationId, or it will be 'com.github.metacubex.clash' + custom.application.id=com.my.compile.clash + # remove application id suffix, or the applicaion id will be 'com.github.metacubex.clash.alpha' + remove.suffix=true + +5. Create `signing.properties` in project root with ```properties keystore.path=/path/to/keystore/file @@ -41,7 +49,7 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta) key.password= ``` -5. Build +6. Build ```bash ./gradlew app:assembleAlphaRelease diff --git a/build.gradle.kts b/build.gradle.kts index 6e1614b31..6c06ffc30 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,11 +31,23 @@ subprojects { apply(plugin = if (isApp) "com.android.application" else "com.android.library") + fun queryConfigProperty(key: String): Any? { + val localProperties = Properties() + val localPropertiesFile = rootProject.file("local.properties") + if (localPropertiesFile.exists()) { + localProperties.load(localPropertiesFile.inputStream()) + } else { + return null + } + return localProperties.getProperty(key) + } + extensions.configure { buildFeatures.buildConfig = true defaultConfig { if (isApp) { - applicationId = "com.github.metacubex.clash" + val customApplicationId = queryConfigProperty("custom.application.id") as? String? + applicationId = customApplicationId.takeIf { it?.isNotBlank() == true } ?: "com.github.metacubex.clash" } project.name.let { name -> @@ -84,17 +96,22 @@ subprojects { productFlavors { flavorDimensions("feature") + val removeSuffix = (queryConfigProperty("remove.suffix") as? String)?.toBoolean() == true + create("alpha") { isDefault = true dimension = flavorDimensionList[0] - versionNameSuffix = ".Alpha" + if (!removeSuffix) { + versionNameSuffix = ".Alpha" + } + buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")") resValue("string", "launch_name", "@string/launch_name_alpha") resValue("string", "application_name", "@string/application_name_alpha") - if (isApp) { + if (isApp && !removeSuffix) { applicationIdSuffix = ".alpha" } } @@ -102,14 +119,16 @@ subprojects { create("meta") { dimension = flavorDimensionList[0] - versionNameSuffix = ".Meta" + if (!removeSuffix) { + versionNameSuffix = ".Meta" + } buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")") resValue("string", "launch_name", "@string/launch_name_meta") resValue("string", "application_name", "@string/application_name_meta") - if (isApp) { + if (isApp && !removeSuffix) { applicationIdSuffix = ".meta" } }