jar包沖突
報(bào)錯(cuò)信息
Duplicate class com.google.gson.stream.MalformedJsonException found in modules jetified-gson-2.8.6 (com.google.code.gson:gson:2.8.6) and**** (******.jar)
Error:Could not find method exclude() for arguments [{group=com.google.code.gson, module=gson}] on directory '{include=*.jar, dir=libs}' of type org.gradle.api.internal.file.collections.DefaultConfigurableFileTree.
解決辦法
最后試來(lái)試去,才發(fā)現(xiàn)exclude需要寫在App 主Module 的build.gradle文件中才能生效存捺,而且注意 project(‘:Speech’) 外面那層括號(hào):
apply plugin: 'com.android.application' //注意這是主Module
repositories {
mavenCentral()
}
dependencies {
// Module dependency
implementation(project(':Speech')){
//解決Gson重復(fù)依賴問題,與passport-1.4.2.jar有沖突
exclude group: 'com.google.code.gson', module: 'gson'
}
}
so庫(kù)沖突
報(bào)錯(cuò)信息
More than one file was found with OS independent path 'lib/x86/libfbjni.so'. If you are using jniLibs and CMake IMPORTED targets,
解決方案
這種是網(wǎng)上普遍的解決方案曙蒸,有的時(shí)候雖然so庫(kù)名字相同捌治,但是邏輯不同,名字重復(fù)的時(shí)候選擇第一個(gè)不太科學(xué)纽窟;
packagingOptions {
pickFirst 'lib/armeabi-v7a/libfbjni.so'
pickFirst 'lib/arm64-v8a/libfbjni.so'
pickFirst 'lib/x86_64/libfbjni.so'
pickFirst 'lib/x86/libfbjni.so'
}
我們可以在:app主項(xiàng)目build.gradle文件最后中添加以下腳本打印出所有so庫(kù)目錄肖油,對(duì)可以修改so庫(kù)刪除或者改名進(jìn)行屏蔽。
tasks.whenTaskAdded { task ->
if (task.name == 'mergeDebugNativeLibs') {
println("------------------- mergeDebugNativeLibs -------------------")
task.doFirst {
println("------------------- find so files start -------------------")
it.inputs.files.each { file ->
printDir(new File(file.absolutePath))
}
println("------------------- find so files end -------------------")
}
}
}
def printDir(File file) {
if (file != null) {
if (file.isDirectory()) {
file.listFiles().each {
printDir(it)
}
} else if (file.absolutePath.endsWith(".so")) {
println "find so file: $file.absolutePath"
}
}
}