Skip to content

Commit e4042d5

Browse files
authored
supports user-defined application_id/package_name (#628)
1 parent 06677c4 commit e4042d5

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta)
3232
sdk.dir=/path/to/android-sdk
3333
```
3434

35-
4. Create `signing.properties` in project root with
35+
4. (Optional) Custom app package name. Add the following configuration to `local.properties`.
36+
37+
```properties
38+
# config your ownn applicationId, or it will be 'com.github.metacubex.clash'
39+
custom.application.id=com.my.compile.clash
40+
# remove application id suffix, or the applicaion id will be 'com.github.metacubex.clash.alpha'
41+
remove.suffix=true
42+
43+
5. Create `signing.properties` in project root with
3644

3745
```properties
3846
keystore.path=/path/to/keystore/file
@@ -41,7 +49,7 @@ Feature of [Clash.Meta](https://github.com/MetaCubeX/Clash.Meta)
4149
key.password=<key password>
4250
```
4351

44-
5. Build
52+
6. Build
4553

4654
```bash
4755
./gradlew app:assembleAlphaRelease

build.gradle.kts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,23 @@ subprojects {
3131

3232
apply(plugin = if (isApp) "com.android.application" else "com.android.library")
3333

34+
fun queryConfigProperty(key: String): Any? {
35+
val localProperties = Properties()
36+
val localPropertiesFile = rootProject.file("local.properties")
37+
if (localPropertiesFile.exists()) {
38+
localProperties.load(localPropertiesFile.inputStream())
39+
} else {
40+
return null
41+
}
42+
return localProperties.getProperty(key)
43+
}
44+
3445
extensions.configure<BaseExtension> {
3546
buildFeatures.buildConfig = true
3647
defaultConfig {
3748
if (isApp) {
38-
applicationId = "com.github.metacubex.clash"
49+
val customApplicationId = queryConfigProperty("custom.application.id") as? String?
50+
applicationId = customApplicationId.takeIf { it?.isNotBlank() == true } ?: "com.github.metacubex.clash"
3951
}
4052

4153
project.name.let { name ->
@@ -84,32 +96,39 @@ subprojects {
8496
productFlavors {
8597
flavorDimensions("feature")
8698

99+
val removeSuffix = (queryConfigProperty("remove.suffix") as? String)?.toBoolean() == true
100+
87101
create("alpha") {
88102
isDefault = true
89103
dimension = flavorDimensionList[0]
90-
versionNameSuffix = ".Alpha"
104+
if (!removeSuffix) {
105+
versionNameSuffix = ".Alpha"
106+
}
107+
91108

92109
buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")")
93110

94111
resValue("string", "launch_name", "@string/launch_name_alpha")
95112
resValue("string", "application_name", "@string/application_name_alpha")
96113

97-
if (isApp) {
114+
if (isApp && !removeSuffix) {
98115
applicationIdSuffix = ".alpha"
99116
}
100117
}
101118

102119
create("meta") {
103120

104121
dimension = flavorDimensionList[0]
105-
versionNameSuffix = ".Meta"
122+
if (!removeSuffix) {
123+
versionNameSuffix = ".Meta"
124+
}
106125

107126
buildConfigField("boolean", "PREMIUM", "Boolean.parseBoolean(\"false\")")
108127

109128
resValue("string", "launch_name", "@string/launch_name_meta")
110129
resValue("string", "application_name", "@string/application_name_meta")
111130

112-
if (isApp) {
131+
if (isApp && !removeSuffix) {
113132
applicationIdSuffix = ".meta"
114133
}
115134
}

0 commit comments

Comments
 (0)