赞
踩
部分集成的第三方SDK会通过Gradle.manifestPlaceholders字段注入在AndroidManifest中
两种方法如下:
1:通过Gradle.Flavor配置,代码如下
productFlavors {
JPushDebug {
applicationId packageName
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "appkey", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "defaultChannel", //暂时填写默认值即可.
]
}
JPushRelease {
applicationId packageName
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "appkey", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "defaultChannel", //暂时填写默认值即可.
]
}
}
这种方式在打包的时候会产生额外的Build Variants(构建变量),改动较大。
下面详细介绍第二种方式:
2:通过Gradle.buildTypes字段配置,代码如下:
buildTypes {
debug {
shrinkResources false // 移除无用的resource文件
minifyEnabled false //不启用混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
'proguard-fresco.pro'
//签名配置
signingConfig signingConfigs.debug
manifestPlaceholders = [
JPUSH_PKGNAME: packageName,
JPUSH_APPKEY : "appkey", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "defaultChannel", //暂时填写默认值即可.
]
}
release {
shrinkResources false // 移除无用的resource文件
minifyEnabled true //启用混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//签名配置
signingConfig signingConfigs.release
manifestPlaceholders = [
JPUSH_PKGNAME: packageName,
JPUSH_APPKEY : "appkey", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "defaultChannel", //暂时填写默认值即可.
]
}
}
原理讲解:
Gradle.manifestPlaceholders的配置等同于BaseConfigImpl.setManifestPlaceholders(Map<String, Object>)方法,如图所示:
buildTypes下的变量(如:debug、release)对应BuildType类,BuildType继承与BaseConfigImpl类,所以能够调用。如图所示:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。