Android開發(fā)中的錯(cuò)誤及解決辦法總結(jié)
一 概述
開發(fā)工具升級(jí),依賴庫(kù),運(yùn)行環(huán)境(jdk)等都會(huì)造成項(xiàng)目運(yùn)行出現(xiàn)錯(cuò)誤
掌握開發(fā)中常見錯(cuò)誤現(xiàn)象和問(wèn)題及解決辦法,能節(jié)省時(shí)間
本文將不定期更新
二 錯(cuò)誤類
2.1 Cannot inline bytecode built with JVM target 1.8
現(xiàn)象
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target
解決方案
android { ... compileOptions { sourceCompatibility = 1.8 targetCompatibility = 1.8 } kotlinOptions { jvmTarget = "1.8" } }
2.2 Unable to find EOCD signature
現(xiàn)象1
Execution failed for task ':app:packagexxxxRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Unable to find EOCD signature
現(xiàn)象2
Execution failed for task ':app:packageGame_ZHRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> java.lang.IllegalArgumentException (no error message)
原因
依賴中添加了有關(guān)ABI相關(guān)的配置,打包輸出時(shí),未指定ABI版本
解決辦法(添加ABI輸出)
import com.android.build.OutputFile static def releaseTime() { return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+8")) } buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' applicationVariants.all { variant -> variant.outputs.all { output -> project.ext { appName = 'YourApkName' } outputFileName = "${appName}-${output.getFilter(OutputFile.ABI)}-${variant.name}-${variant.versionName}.apk" } } } }
2.3 failed to read PNG signature: file does not start with PNG signature
現(xiàn)象
AAPT: error: failed to read PNG signature: file does not start with PNG signature.
解決辦法
在app/build.gradle文件中加以下代碼后,重構(gòu)項(xiàng)目
android { compileSdkVersion 28 flavorDimensions "mode" aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false defaultConfig { }
2.4 Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8
現(xiàn)象(項(xiàng)目創(chuàng)建時(shí))
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
解決辦法
依次點(diǎn)擊:File——>Project Struct——>SDK Location——>JDK location was moved to Gradle Settings,在打開的對(duì)話框中,將Gradle JDK修改為11
三 警告類
3.1 The ‘kotlin-android-extensions’ Gradle plugin is deprecated
現(xiàn)象
The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
解決辦法
刪除 apply plugin: 'kotlin-android-extensions'
使用binding賦值
binding.name.text = viewModel.nameString
3.2 Warning: Mapping new ns xx/common/02 to old ns xx/common/01
現(xiàn)象
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
解決辦法(buildToolsVersion引起-修改前)
compileSdkVersion 30 buildToolsVersion "30.0.3"
去掉buildToolsVersion或?qū)uildToolsVersion版本降低
compileSdkVersion 30 buildToolsVersion "30.0.2"
四 工具類
4.1 Task list not build
現(xiàn)象
解決辦法
- 點(diǎn)擊Task list not build,進(jìn)入Settings——>Experimental,將Do not build Gradle task list duraing Gradle sync前面的勾選去掉,并應(yīng)用
- 點(diǎn)擊Sync Project with Gradle Files同步一下項(xiàng)目
總結(jié)
到此這篇關(guān)于Android開發(fā)中的錯(cuò)誤及解決辦法的文章就介紹到這了,更多相關(guān)Android開發(fā)錯(cuò)誤及解決內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android 三級(jí)NestedScroll嵌套滾動(dòng)實(shí)踐
這篇文章主要介紹了Android 三級(jí)NestedScroll嵌套滾動(dòng)實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02Android中利用xml文件布局修改Helloworld程序
這篇文章主要介紹了Android中利用xml文件布局修改Helloworld程序 的相關(guān)資料,需要的朋友可以參考下2016-07-07Android Activity之間傳遞圖片(Bitmap)的方法
這篇文章介紹了Android Activity之間傳遞圖片(Bitmap)的方法,有需要的朋友可以參考一下2013-08-08快速解決android webview https圖片不顯示的問(wèn)題
今天小編就為大家分享一篇快速解決android webview https圖片不顯示的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07Android開發(fā)InputManagerService創(chuàng)建與啟動(dòng)流程
這篇文章主要為大家介紹了Android開發(fā)InputManagerService創(chuàng)建與啟動(dòng)流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Android?Hilt?Retrofit?Paging3使用實(shí)例
這篇文章主要介紹了Android?Hilt依賴注入的使用,首先,某個(gè)類的成員變量稱為依賴,如若此變量想要實(shí)例化引用其類的方法,可以通過(guò)構(gòu)造函數(shù)傳參或者通過(guò)某個(gè)方法獲取對(duì)象,此等通過(guò)外部方法獲取對(duì)象實(shí)例的稱為依賴注入2023-01-01Android UI實(shí)現(xiàn)底部切換標(biāo)簽fragment
這篇文章主要為大家詳細(xì)介紹了Android UI實(shí)現(xiàn)底部切換標(biāo)簽的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12