manifestPlaceholders = [
app_name: “开-WalleDemo”,
app_icon: “@drawable/icon_develop”
]
}
//测试环境
check {
buildConfigField “int”, “ENV_TYPE”, “2”
applicationId ‘om.soubu.walledemo.check’
manifestPlaceholders = [
app_name: “测-WalleDemo”,
app_icon: “@drawable/icon_check”
]
}
//生产环境
product {
buildConfigField “int”, “ENV_TYPE”, “3”
applicationId ‘com.soubu.walledemo.product’
manifestPlaceholders = [
app_name: “WalleDemo”,
app_icon: “@drawable/icon_product”
]
}
}
}
dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2’, {
exclude group: ‘com.android.support’, module: ‘support-annotations’
})
compile ‘com.android.support:appcompat-v7:25.1.0’
testCompile ‘junit:junit:4.12’
compile ‘com.meituan.android.walle:library:1.0.3’
}
(3) 这里,我根据不同的环境生成了不同包名的apk,方便在手机上同时安装多个环境的应用。为了让gradle动态更改apk的名称和图标,我们需要在manifest文件中使用{app_name}等占位符
(4) 在代码中获取多渠道信息
String channel = WalleChannelReader.getChannel(getApplicationContext());
(5) 在代码中获取多环境信息
int envType = BuildConfig.ENV_TYPE;
这里的BuildConfig是由gradle动态生成的:
package com.soubu.walledemo;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean(“true”);
public static final String APPLICATION_ID = “om.soubu.walledemo.develop”;