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中加入这段,可以把报错的资源显示出现,然后逐个去解决.
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
2.问题二:
添加系统android.jar有可能出现这个错误;
Execution failed for task ':app:mergeExtDexDebug' 65535
查考这个issues
解决方法
在Module 的 build.gradle中添加这些内容
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
3.问题三:
方法超了 65536
解决方法
在Module 的 build.gradle中添加这些内容
android {
...
defaultConfig {
...
multiDexEnabled true
}
}
...
dependencies {
...
compile 'com.android.support:multidex:1.0.1'
}
自定义Application并继承MultiDexApplication;
但是如果已经继承了Application,那么也可以通过重写attachBaseContext(Context base)方法
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
最后在AndroidManifest.xml里把application改成引用自定义的Application
4.问题四:
项目运行的时候报出这个错误
Execution failed for task ':xxxxx:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
这个是检查对比,发现一下资源上的问题,提示上给出的解决方法是在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指定本地对应的NDK版本
ndk.dir=C\:\\Users\\zqian\\AppData\\Local\\Android\\Sdk\\ndk\\21.4.7075529
6.问题6
输出详细的编译错误
7.导包冲突
查找冲突的方式,运行dependencies就能列出所有依赖库之间对应内部依赖的版本
剔除依赖的方式,例如:test模块中也有android.core,那么可以在导入test模块的时候移除对应android.core的引用,是用自己模块导入的android.core版本
implementation(project(":test")){
exclude(mapOf("group" to "androidx.core"))//这个方法根据组来移除
exclude(mapOf("module" to "core-ktx"))//这个方法根据artifact name来移除
exclude(group = "androidx.core",module = "core-ktx")//这个方法是明确指定移除的依赖库
}
问题7
导入新的项目提示这个错误,这个是因为gradle-wrapper.properties配置的gradle版本和Android studio对不上,可以去能正常运行的项目里拷贝一个能用的版本
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)