编程语言
首页 > 编程语言> > Java-Android Studio意外的最高级别例外:

Java-Android Studio意外的最高级别例外:

作者:互联网

今天,我面临着一个巨大的错误,该错误使我无法在手机上运行示例项目.

Android Studio构建项目时,它首先将以下目标显示为UP-TO-DATE:

....
:demoproject:processDebugResources UP-TO-DATE
:demoproject:generateDebugSources UP-TO-DATE
:demoproject:compileDebugJava UP-TO-DATE
:demoproject:proguardDebug UP-TO-DATE
....

在构建过程中,有数十条这样的UP-TO-DATE日志语句.但是,它们始终在:demoproject:dexDebug处停止.对于dexDebug,我似乎从来没有得到UP-TO-DATE日志语句.

而是,dexDebug后面跟随此错误:

:demoproject:dexDebug
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.xyz.corp.sample.project.demo.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

现在,有许多此类忽略InnerClasses属性错误.它们甚至出现在v4支持库中的类上,这确实令人困惑.

最后,这些错误以新的语句结尾:

UNEXPECTED TOP-LEVEL EXCEPTION:
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
Error:Execution failed for task ':demoproject:dexDebug'.
> com.android.ide.common.process.ProcessException:    org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)

我已经参考了以下链接:

1. Gradle finished with non-zero exit value 1.

2. What is the “Ignoring InnerClasses attribute” warning output during compilation?.

我不确定它们是否适用于我的情况.我什至无法运行该项目.我已经将IDE更新为SDK Tools 22.0.1,并修改了build.gradle文件中的buildToolsVersion标记,但无济于事.有人可以指导我如何处理此错误吗?所有帮助将不胜感激.

哦,这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    defaultConfig {
        applicationId "com.xyz.corp.demo.project"
        minSdkVersion 10
        targetSdkVersion 22

        versionCode 2060200
        versionName '2.6.02.00'
    }

    buildTypes {
        debug {

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def file = output.outputFile
                    output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
                }
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.0'

    compile project(':xyzSDK')
}

请帮忙 !!!

解决方法:

因为它正在报告:错误的类文件魔术(cafebabe)或版本(0034.0000),所以您应检查是否使用与运行时尝试使用的Java版本相同的Java版本进行编译.
如果使用的是gradle,则应在build.gradle文件中使用以下条目或类似条目:

apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

使用此link获取更多gradle详细信息.

在Android Studio中,从文件->项目结构-> SDK位置->在JDK位置,您应该使用jdk 1.7,而不要在Project级别设置上进行中继.有关类似的Android Studio问题,请参见此link.

标签:android-studio,android-sdk-tools,java,android,android-gradle-plugin
来源: https://codeday.me/bug/20191120/2041556.html