gradle 配置参数
23 Sep 2015manifestPlaceholders
的使用
build.gradle
android {
defaultConfig {
...
manifestPlaceholders += [foo: "abc"]
manifestPlaceholders += [foo2: "def"]
}
buildTypes {
release {
manifestPlaceholders += [foo2: "def123566"]
}
}
}
AndroidManifest.xml
<meta-data
android:name="blog"
android:value="${foo}" />
<meta-data
android:name="linguofeng.com"
android:value="${foo2}" />
buildConfigField
的使用
build.gradle
android {
defaultConfig {
...
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "String", "LOG_NAME", "\"linguofeng.com\""
}
buildTypes {
release {
buildConfigField "String", "LOG_NAME", "\"blog.linguofeng.com\""
}
}
}
BuildConfig.java 该文件会自动生成
public final class BuildConfig {
// ...
// Fields from default config.
public static final boolean LOG_DEBUG = true;
public static final String LOG_NAME = "linguofeng.com";
}
MyClass.java
if (BuildConfig.LOG_DEBUG) {
// print log
}
resValue
的使用
build.gradle
android {
defaultConfig {
resValue "string", "name", "linguofeng"
}
buildTypes {
release {
resValue "string", "name", "linguofeng.com"
}
}
}
AndroidManifest.xml
<application android:label="@string/name" />
Gradle Daemon
touch ~/.gradle/gradle.properties && echo "org.gradle.daemon=true" >> ~/.gradle/gradle.properties