Android studio 編譯報錯

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ì)的編譯錯誤


image.png

7.導(dǎo)包沖突

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


image.png

剔除依賴的方式,例如: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)
image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容