Skip to content

Commit fccad09

Browse files
committed
Fix unknown property error when syncing Gradle
When opening project for the first time Android Gradle might create default 'local.properties' file. Gradle will attempt to read multiple properties once it detects that this file exists but will fail to find them later.
1 parent 3175c16 commit fccad09

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

app/build.gradle

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,24 @@ android {
3535
Properties p = new Properties()
3636
new FileInputStream(propsFile).withCloseable { is -> p.load(is) }
3737
p.each { name, value -> ext[name] = value }
38-
} else {
39-
ext["GLIA_API_KEY_SECRET"] = System.getenv("GLIA_API_KEY_SECRET") as String
40-
ext["GLIA_API_KEY_ID"] = System.getenv("GLIA_API_KEY_ID") as String
41-
ext["GLIA_SITE_ID"] = System.getenv("GLIA_SITE_ID") as String
42-
ext["FIREBASE_PROJECT_ID"] = System.getenv("FIREBASE_PROJECT_ID") as String
43-
ext["FIREBASE_API_KEY"] = System.getenv("FIREBASE_API_KEY") as String
44-
ext["FIREBASE_APP_ID"] = System.getenv("FIREBASE_APP_ID") as String
45-
ext["FIREBASE_APP_ID_DEBUG"] = System.getenv("FIREBASE_APP_ID_DEBUG") as String
46-
ext["FIREBASE_APP_ID_MASTER"] = System.getenv("FIREBASE_APP_ID_MASTER") as String
4738
}
39+
40+
initEnvProperty('GLIA_API_KEY_SECRET')
41+
initEnvProperty('GLIA_API_KEY_ID')
42+
initEnvProperty('GLIA_SITE_ID')
43+
initEnvProperty('FIREBASE_PROJECT_ID')
44+
initEnvProperty('FIREBASE_API_KEY')
45+
initEnvProperty('FIREBASE_APP_ID')
46+
initEnvProperty('FIREBASE_APP_ID_DEBUG')
47+
initEnvProperty('FIREBASE_APP_ID_MASTER')
48+
4849
buildTypes {
4950
all {
50-
resValue("string", "site_id", GLIA_SITE_ID ?: "")
51-
resValue("string", "glia_api_key_id", GLIA_API_KEY_ID ?: "")
52-
resValue("string", "glia_api_key_secret", GLIA_API_KEY_SECRET ?: "")
53-
resValue("string", "firebase_proj_id", FIREBASE_PROJECT_ID ?: "")
54-
resValue("string", "firebase_api_key", FIREBASE_API_KEY ?: "")
51+
resValue("string", "site_id", GLIA_SITE_ID)
52+
resValue("string", "glia_api_key_id", GLIA_API_KEY_ID)
53+
resValue("string", "glia_api_key_secret", GLIA_API_KEY_SECRET)
54+
resValue("string", "firebase_proj_id", FIREBASE_PROJECT_ID)
55+
resValue("string", "firebase_api_key", FIREBASE_API_KEY)
5556
}
5657
debug {
5758
signingConfig signingConfigs.debug
@@ -83,6 +84,12 @@ android {
8384
namespace 'com.glia.exampleapp'
8485
}
8586

87+
def initEnvProperty(String propertyName) {
88+
if (!project.hasProperty(propertyName)) {
89+
ext[propertyName] = System.getenv(propertyName) as String ?: "UNDEFINED"
90+
}
91+
}
92+
8693
dependencies {
8794
implementation "androidx.appcompat:appcompat:$appCompatVersion"
8895
implementation "com.google.android.material:material:$materialVersion"

0 commit comments

Comments
 (0)