It is really easy to define gradle-generated constants and use those constants in android java code.
For example, I want to use a build type dependent constant RETRY_COUNT.
Gradle's class BuildType has a method:
public void buildConfigField(String type, String name, String value)
This method can be used like this:
android {
...
buildTypes {
release {
buildConfigField "int", "RETRY_COUNT", "3"
...
}
debug {
buildConfigField "int", "RETRY_COUNT", "10"
...
}
}
}
Next, I rebuild my project, open BuildConfig and see:
public final class BuildConfig {
...
public static final boolean RETRY_COUNT = 10;
}
For example, I want to use a build type dependent constant RETRY_COUNT.
Gradle's class BuildType has a method:
public void buildConfigField(String type, String name, String value)
This method can be used like this:
android {
...
buildTypes {
release {
buildConfigField "int", "RETRY_COUNT", "3"
...
}
debug {
buildConfigField "int", "RETRY_COUNT", "10"
...
}
}
}
public final class BuildConfig {
...
public static final boolean RETRY_COUNT = 10;
}
Комментариев нет:
Отправить комментарий