返回顶部
首页 > 资讯 > 移动开发 >Android开发中的错误及解决办法总结
  • 858
分享到

Android开发中的错误及解决办法总结

2024-04-02 19:04:59 858人浏览 八月长安
摘要

目录一 概述二 错误类2.1 Cannot inline bytecode built with JVM target 1.82.2 Unable to find EOCD sign

一 概述

开发工具升级,依赖库,运行环境(jdk)等都会造成项目运行出现错误

掌握开发中常见错误现象和问题及解决办法,能节省时间

本文将不定期更新

二 错误类

2.1 Cannot inline bytecode built with JVM target 1.8

现象

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

现象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

现象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

现象

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

现象(项目创建时)

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

现象

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

现象

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

现象

解决办法

  1. 点击Task list not build,进入Settings——>Experimental,将Do not build Gradle task list duraing Gradle sync前面的勾选去掉,并应用
  2. 点击Sync Project with Gradle Files同步一下项目

总结

到此这篇关于Android开发中的错误及解决办法的文章就介绍到这了,更多相关Android开发错误及解决内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Android开发中的错误及解决办法总结

本文链接: https://lsjlt.com/news/139492.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作