Android開發(fā)中的錯誤及解決辦法總結
一 概述
開發(fā)工具升級,依賴庫,運行環(huán)境(jdk)等都會造成項目運行出現(xiàn)錯誤
掌握開發(fā)中常見錯誤現(xiàn)象和問題及解決辦法,能節(jié)省時間
本文將不定期更新
二 錯誤類
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)
原因
依賴中添加了有關ABI相關的配置,打包輸出時,未指定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文件中加以下代碼后,重構項目
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)象(項目創(chuàng)建時)
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`.
解決辦法
依次點擊:File——>Project Struct——>SDK Location——>JDK location was moved to Gradle Settings,在打開的對話框中,將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或將buildToolsVersion版本降低
compileSdkVersion 30 buildToolsVersion "30.0.2"
四 工具類
4.1 Task list not build
現(xiàn)象

解決辦法
- 點擊Task list not build,進入Settings——>Experimental,將Do not build Gradle task list duraing Gradle sync前面的勾選去掉,并應用
- 點擊Sync Project with Gradle Files同步一下項目
總結
到此這篇關于Android開發(fā)中的錯誤及解決辦法的文章就介紹到這了,更多相關Android開發(fā)錯誤及解決內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Android中利用xml文件布局修改Helloworld程序
這篇文章主要介紹了Android中利用xml文件布局修改Helloworld程序 的相關資料,需要的朋友可以參考下2016-07-07
Android Activity之間傳遞圖片(Bitmap)的方法
這篇文章介紹了Android Activity之間傳遞圖片(Bitmap)的方法,有需要的朋友可以參考一下2013-08-08
快速解決android webview https圖片不顯示的問題
今天小編就為大家分享一篇快速解決android webview https圖片不顯示的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Android開發(fā)InputManagerService創(chuàng)建與啟動流程
這篇文章主要為大家介紹了Android開發(fā)InputManagerService創(chuàng)建與啟動流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
Android?Hilt?Retrofit?Paging3使用實例
這篇文章主要介紹了Android?Hilt依賴注入的使用,首先,某個類的成員變量稱為依賴,如若此變量想要實例化引用其類的方法,可以通過構造函數(shù)傳參或者通過某個方法獲取對象,此等通過外部方法獲取對象實例的稱為依賴注入2023-01-01
Android UI實現(xiàn)底部切換標簽fragment
這篇文章主要為大家詳細介紹了Android UI實現(xiàn)底部切換標簽的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12

