文章目录
- 一、报错信息
- 二、问题分析
- 三、解决方案
- 1、解决方案 1
- 2、解决方案 2
一、报错信息
运行 tinker 官方示例 https://github.com/Tencent/tinker/tree/dev/tinker-sample-android , 编译时 , 报如下错误 ;
代码语言:javascript复制FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:tinkerProcessDebugManifest'.
> tinkerId is not set!!!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
9 actionable tasks: 9 executed
二、问题分析
需要阅读 Gradle 脚本 , 分析报错原因 ;
仔细阅读 build.gradle 构建脚本 , 配置 TINKER_ID 的代码如下 ,
代码语言:javascript复制buildConfigField "String", "TINKER_ID", ""${getTinkerIdValue()}""
通过 getTinkerIdValue 方法 , 获取 TINKER_ID , 在 getTinkerIdValue 方法中会查询是否有 TINKER_ID 属性 , 或者调用 gitSha 方法获取 TINKER_ID 参数 ;
代码语言:javascript复制def getTinkerIdValue() {
return hasProperty("TINKER_ID") ? TINKER_ID : gitSha()
}
def gitSha() {
try {
String gitRev = 'git rev-parse --short HEAD'.execute(null, project.rootDir).text.trim()
if (gitRev == null) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
return gitRev
} catch (Exception e) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
}
因此这里有两种方式设置 TINKER_ID ,
- 在 gradle.properties 配置中 , 设置 TINKER_ID 参数 ;
- gitSha 方法返回非空字符串 ;
三、解决方案
1、解决方案 1
在 gradle.properties 配置中 , 设置 TINKER_ID 参数 ,
代码语言:javascript复制TINKER_ID=1.0
TINKER_ENABLE=true
2、解决方案 2
修改 https://github.com/Tencent/tinker/blob/dev/tinker-sample-android/app/build.gradle 构建脚本代码 , 使 gitSha 方法返回非空字符串 ;
代码语言:javascript复制def gitSha() {
try {
String gitRev = "1.0"
if (gitRev == null) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
return gitRev
} catch (Exception e) {
throw new GradleException("can't get git rev, you should add git to system path or just input test value, such as 'testTinkerId'")
}
}