1.問題一:
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{}],"original":"AAPT: W/ziparchive(10643): Zip: bad offsets (dir 37221899, size 713971, eocd 37935861)\nerror: failed to open APK: Invalid offset.\n\n ","tool":"AAPT"}
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processRomallDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
AAPT: W/ziparchive(10643): Zip: bad offsets (dir 37221899, size 713971, eocd 37935861)
error: failed to open APK: Invalid offset.
問題原因:
項目的資源報錯了.
解決方法
在項目的更目錄下的build.gradle中加入這段,可以把報錯的資源顯示出現(xiàn),然后逐個去解決.
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
2.問題二:
添加系統(tǒng)android.jar有可能出現(xiàn)這個錯誤;
Execution failed for task ':app:mergeExtDexDebug' 65535
查考這個issues
解決方法
在Module 的 build.gradle中添加這些內(nèi)容
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
3.問題三:
方法超了 65536
解決方法
在Module 的 build.gradle中添加這些內(nèi)容
android {
...
defaultConfig {
...
multiDexEnabled true
}
}
...
dependencies {
...
compile 'com.android.support:multidex:1.0.1'
}
自定義Application并繼承MultiDexApplication;
但是如果已經(jīng)繼承了Application,那么也可以通過重寫attachBaseContext(Context base)方法
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
最后在AndroidManifest.xml里把a(bǔ)pplication改成引用自定義的Application
4.問題四:
項目運(yùn)行的時候報出這個錯誤
Execution failed for task ':xxxxx:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
這個是檢查對比,發(fā)現(xiàn)一下資源上的問題,提示上給出的解決方法是在module的gradle文件上添加這段
//Lint found fatal errors while assembling a release target.
//To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
但是這個只是解決了不能編譯的問題,最終的解決可以查看module目錄的下的build/reports/lint-results-release-fatal-html文件,這里記錄的報錯的原因
5.問題五
What went wrong:
Execution failed for task ':app:stripDebugDebugSymbols'.
No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi
可以在local.properties指定本地對應(yīng)的NDK版本
ndk.dir=C\:\\Users\\zqian\\AppData\\Local\\Android\\Sdk\\ndk\\21.4.7075529
6.問題6
輸出詳細(xì)的編譯錯誤

7.導(dǎo)包沖突
查找沖突的方式,運(yùn)行dependencies就能列出所有依賴庫之間對應(yīng)內(nèi)部依賴的版本

剔除依賴的方式,例如:test模塊中也有android.core,那么可以在導(dǎo)入test模塊的時候移除對應(yīng)android.core的引用,是用自己模塊導(dǎo)入的android.core版本
implementation(project(":test")){
exclude(mapOf("group" to "androidx.core"))//這個方法根據(jù)組來移除
exclude(mapOf("module" to "core-ktx"))//這個方法根據(jù)artifact name來移除
exclude(group = "androidx.core",module = "core-ktx")//這個方法是明確指定移除的依賴庫
}
問題7
導(dǎo)入新的項目提示這個錯誤,這個是因為gradle-wrapper.properties配置的gradle版本和Android studio對不上,可以去能正常運(yùn)行的項目里拷貝一個能用的版本
General error during conversion: Unsupported class file major version 61
java.lang.IllegalArgumentException: Unsupported class file major version 61
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:189)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:170)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:156)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:277)
