Skip to content

Instantly share code, notes, and snippets.

@dEn13L
Created December 18, 2024 11:12
Show Gist options
  • Select an option

  • Save dEn13L/caeab0ce4e6c7662e398e94a5d6fbffe to your computer and use it in GitHub Desktop.

Select an option

Save dEn13L/caeab0ce4e6c7662e398e94a5d6fbffe to your computer and use it in GitHub Desktop.
def getSecureProperty(String propertyName) throws MissingSecurePropertyException {
def property = project.findProperty(propertyName) ?: System.getenv(propertyName)
if (property != null) {
return property
} else {
throw new MissingSecurePropertyException(propertyName)
}
}
class MissingSecurePropertyException extends RuntimeException {
private final String property
MissingSecurePropertyException(String property) {
super()
this.property = property
}
@Override
String getMessage() {
return "The property \"${property}\" is not found. " +
"Please add this property to ~/.gradle/gradle.properties."
}
}
ext {
getSecureProperty = this.&getSecureProperty
}
@dEn13L
Copy link
Author

dEn13L commented Jan 8, 2025

Также нужно включить фичу buildConfig

android {
    buildFeatures {
        buildConfig = true
    }
}

@dEn13L
Copy link
Author

dEn13L commented Jan 8, 2025

Но можно не создавать отдельный файл

Пример для gradle.kts

android {
    defaultConfig {
        buildConfigField(
            type = "String",
            name = "MAPKIT_API_KEY",
            value = "\"${project.findProperty("yandexMapKitApiKey")}\"",
        )
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment