Open flk123 opened 4 years ago
tinker 新版本规则造成的,我用的解决方法:在 gradle 中加入以下代码:
tasks.whenTaskAdded { task ->
android.applicationVariants.all { variant ->
if (task.name == "tinkerProcess${variant.name.capitalize()}MultidexKeep") {
task.finalizedBy "fixTinkerDexKeepProguardFor${variant.name.capitalize()}"
}
}
}
android.applicationVariants.all { variant ->
Task fixTinkerDexKeepProguard = task("fixTinkerDexKeepProguardFor${variant.name.capitalize()}")
fixTinkerDexKeepProguard.doLast {
def tinkerMultidexKeepTask = project.tasks.findByName("tinkerProcess${variant.name.capitalize()}MultidexKeep")
def multiDexKeepProguardFile = file(tinkerMultidexKeepTask.multiDexKeepProguard)
def lines = []
// 记录从某条规则开始,后面需要跳过几行
def skipLines = 0
multiDexKeepProguardFile.text.eachLine { line ->
if (line.contains("-keep class com.tencent.tinker.entry.TinkerApplicationInlineFence")) {
skipLines = 2
} else if (skipLines > 0) {
skipLines--
} else {
lines.add(line)
}
}
FileWriter fr = new FileWriter(multiDexKeepProguardFile, false)
try {
for (String line : lines) {
fr.write(line)
fr.write("\n")
}
} finally {
fr.close()
}
}
}
tinker 新版本规则造成的,我用的解决方法:在 gradle 中加入以下代码:
tasks.whenTaskAdded { task -> android.applicationVariants.all { variant -> if (task.name == "tinkerProcess${variant.name.capitalize()}MultidexKeep") { task.finalizedBy "fixTinkerDexKeepProguardFor${variant.name.capitalize()}" } } } android.applicationVariants.all { variant -> Task fixTinkerDexKeepProguard = task("fixTinkerDexKeepProguardFor${variant.name.capitalize()}") fixTinkerDexKeepProguard.doLast { def tinkerMultidexKeepTask = project.tasks.findByName("tinkerProcess${variant.name.capitalize()}MultidexKeep") def multiDexKeepProguardFile = file(tinkerMultidexKeepTask.multiDexKeepProguard) def lines = [] // 记录从某条规则开始,后面需要跳过几行 def skipLines = 0 multiDexKeepProguardFile.text.eachLine { line -> if (line.contains("-keep class com.tencent.tinker.entry.TinkerApplicationInlineFence")) { skipLines = 2 } else if (skipLines > 0) { skipLines-- } else { lines.add(line) } } FileWriter fr = new FileWriter(multiDexKeepProguardFile, false) try { for (String line : lines) { fr.write(line) fr.write("\n") } } finally { fr.close() } } }
有没有测试过?会不会影响热修复?
tinker 新版本规则造成的,我用的解决方法:在 gradle 中加入以下代码:
tasks.whenTaskAdded { task -> android.applicationVariants.all { variant -> if (task.name == "tinkerProcess${variant.name.capitalize()}MultidexKeep") { task.finalizedBy "fixTinkerDexKeepProguardFor${variant.name.capitalize()}" } } } android.applicationVariants.all { variant -> Task fixTinkerDexKeepProguard = task("fixTinkerDexKeepProguardFor${variant.name.capitalize()}") fixTinkerDexKeepProguard.doLast { def tinkerMultidexKeepTask = project.tasks.findByName("tinkerProcess${variant.name.capitalize()}MultidexKeep") def multiDexKeepProguardFile = file(tinkerMultidexKeepTask.multiDexKeepProguard) def lines = [] // 记录从某条规则开始,后面需要跳过几行 def skipLines = 0 multiDexKeepProguardFile.text.eachLine { line -> if (line.contains("-keep class com.tencent.tinker.entry.TinkerApplicationInlineFence")) { skipLines = 2 } else if (skipLines > 0) { skipLines-- } else { lines.add(line) } } FileWriter fr = new FileWriter(multiDexKeepProguardFile, false) try { for (String line : lines) { fr.write(line) fr.write("\n") } } finally { fr.close() } } }
有没有测试过?会不会影响热修复?
在 Android 5.0 及以上手机上试过,是可以的;5.0 以下不行,启动会崩溃!可以通过将 MultiDex.install 搞到 Tinker 初始化前面解决。