都是抄别人的,所以屁话不多说直接上代码:
android {
compileSdkVersion 28
flavorDimensions 'api'
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 14
versionName "1.0.12"
multiDexEnabled true
//X5兼容64位手机
ndk {
abiFilters "armeabi-v7a"
}
manifestPlaceholders = [
JPUSH_PKGNAME: "你的包名",
JPUSH_APPKEY : "极光key", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "developer-default" //暂时填写默认值即可.
]
}
signingConfigs {
release {
keyAlias 'xxx'
keyPassword '123456'
storeFile file('E:/android_workspace/si.jks')
storePassword '123456'
}
}
signingConfigs {
debug {
storeFile file("E:/si.jks")
storePassword "123456"
keyAlias "xxx"
keyPassword "123456"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
//移除无用的资源文件
shrinkResources true
//压缩对齐生成的apk包
zipAlignEnabled true
//启用multidex的支持
multiDexEnabled true
manifestPlaceholders = [qqappid: "1111111111"]
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
//混淆文件配置
signingConfig signingConfigs.debug
manifestPlaceholders = [qqappid: "1111111111"]
proguardFiles 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
androidExtensions {
experimental = true
}
productFlavors {
app {
applicationId "线上包名"
//resValue,相当于在string.xml插入了一条数据,必须这个文件中没有相
//同的名字,比如你的baseUrl在你的string.xml中必须没有,数据类型支持
//string,bool,其他的没用到不知道
resValue("string", "baseUrl", "线上baseurl")
resValue("string", "app_name", "线上应用名")
resValue("bool", "is_check_update", "true")
//如果用到了provider,请在这里配置
resValue("string", "file_provider", "线上包名.provider")
//有时候老是安装冲突,请使用adb安装,他会提示你哪里报错,然后用
//studio打开你的apk的清单文件,查看报错处,把他提出来,写在你自己
//的清单文件中,然后用resValue动态修改包名,比如我这个极光的
//DataProvider,让我查了半天才查到
resValue("string", "jpush_file_provider", "线上包名.DataProvider")
//这里只是告诉我,也可以这样动态修改清单文件中的值,这些代码放这里
//没什么用
manifestPlaceholders = [
JPUSH_APPKEY : "极光key", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
]
}
app_release_test {
applicationId "线上测试包名"
resValue("string", "baseUrl", "线上测试baseurl")
resValue("bool", "is_check_update", "false")
resValue("string", "app_name", "线上测试应用名")
resValue("string", "file_provider", "线上测试包名.provider")
resValue("string", "jpush_file_provider", "线上测试包名.DataProvider")
manifestPlaceholders = [
JPUSH_APPKEY : "极光key", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
]
}
app_test {
applicationId "测试包名"
resValue("string", "baseUrl", "测试baseurl")
resValue("string", "app_name", "测试应用名")
resValue("bool", "is_check_update", "false")
resValue("string", "file_provider", "线上测试包名.provider")
resValue("string", "jpush_file_provider", "线上测试包名.DataProvider")
manifestPlaceholders = [
JPUSH_APPKEY : "极光key", //JPush上注册的包名对应的appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
lintOptions {
abortOnError false
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//多渠道打包配置
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "应用名_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
}
}
}
清单文件中具体设置如下:
<!--自己文件中的provider配置-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="@string/file_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<!--安装冲突找到的provider,将第三方包中的provider覆盖-->
<provider
android:name="cn.jpush.android.service.DataProvider"
android:exported="true"
android:authorities="@string/jpush_file_provider"
tools:replace="android:authorities"/>
然后完事,其他的比如你要动态修改图标,资源文件,签名什么的,可以从上面的代码中悟出来.
网友评论