美文网首页
Android debug/release 修改包名,取不同

Android debug/release 修改包名,取不同

作者: 小GG | 来源:发表于2022-07-20 10:05 被阅读0次

场景: 当一个项目对应多个包名的时候 , agconnect-services.json 文件中需要指定对应包名,这个时候 当我们项目中 只有一个 agconnect-services.json文件时 会报

  • What went wrong:

Execution failed for task ':app:processDebugAGCPlugin'.

ERROR: Failed to verify AGConnect-Config '/client/package_name', expected: 'com.gxx.fast', but was: 'com.gxx.fast.debug'

解决方案:
1.在项目中对应位置创建 文件 对应多个子文件里面分别 复制一个agconnect-services.json 文件
eg:
分别是uat、pro、text 对应不同包名环境

WechatIMG150.png
  1. 在app的build.gradle 文件中进行配置

//判断渠道
def getBuildType() {
int buildType = 0
for (String s : gradle.startParameter.taskNames) {
if (s.contains("AgentTestDebug") || s .contains("AgentTestRelease")) {
buildType = 1
break
}
if (s.contains("AgentUatDebug") || s.contains("AgentUatRelease")) {
buildType = 2
break
}
if (s.contains("AgentProDebug") || s.contains("AgentProRelease")) {
buildType = 3
break
}
}
return buildType
}

android{
//判断当前运行环境
afterEvaluate {
def buildTypes = 0;// 运行环境 1 text 2:uat 3:pro
buildTypes = getBuildType()
tasks.matching {
it.name.contains("AgentTestDebug") || it.name.contains( "AgentTestRelease")
|| it.name.contains( "AgentUatDebug") || it.name.contains( "AgentUatRelease")
|| it.name.contains( "AgentProDebug") || it.name.contains( "AgentProRelease")
}.each { task ->
if (buildTypes == 1) { //debug模式下编译环境
task.dependsOn(copyAgconnecToTest)
} else if (buildTypes == 2) {
task.dependsOn(copyAgconnecToUat)
} else {
task.dependsOn(copyAgconnecToPro)
}
}
}
//复制文件
task copyAgconnecToTest(type: Copy) {
def isFileExists = false;
doFirst {
isFileExists = file("agconnect-services.json").exists();
}
if (isFileExists) {
dependsOn(deleteAgconnecFile)
}
from "src/pushservice/tests/"
include "agconnect-services.json"
into "./"
}
task copyAgconnecToUat(type: Copy) {
def isFileExists = false
doFirst {
isFileExists = file("agconnect-services.json").exists()
}
if (isFileExists) {
dependsOn(deleteAgconnecFile)
}
from "src/pushservice/uat/"
include "agconnect-services.json"
into "./"
}

//复制文件
task copyAgconnecToPro(type: Copy) {
def isFileExists = false
doFirst {
isFileExists = file("agconnect-services.json").exists();
}
if (isFileExists) {
dependsOn(deleteAgconnecFile)
}
from "src/pushservice/pro/"
include "agconnect-services.json"
into "./"
}
}

相关文章

网友评论

      本文标题:Android debug/release 修改包名,取不同

      本文链接:https://www.haomeiwen.com/subject/apruirtx.html