Created
December 18, 2024 11:12
-
-
Save dEn13L/caeab0ce4e6c7662e398e94a5d6fbffe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Author
Author
Также нужно включить фичу buildConfig
android {
buildFeatures {
buildConfig = true
}
}
Author
Но можно не создавать отдельный файл
Пример для 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
gradle.propertiesв корне вашего юзера в системе (Users/<username>/.gradle/gradle.properties)systemProp.org.gradle.project.yandexMapKitApiKey=<API_KEY>secure-properties-provider.gradleapp/build.gradleдобавитьПосле этого в коде можно получить ключ как
BuildConfig.MAPKIT_API_KEY