Android Studio 意外的顶级例外: [英] Android Studio UNEXPECTED TOP-LEVEL EXCEPTION:
问题描述
今天我遇到了一个巨大的错误,我无法在手机上运行示例项目.
Today I am faced with a massive error that doesn't let me run a sample project on my phone.
Android Studio 在构建项目时,首先将以下目标显示为 UP-TO-DATE
:
When Android Studio is building the project, it first shows the following targets as 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
日志语句.
There are dozens of these UP-TO-DATE
log statements during the build process. However, they always halt at :demoproject:dexDebug
. For dexDebug
, I never seem to get an UP-TO-DATE
log statement.
相反,dexDebug
后面跟着这个错误:
Instead, dexDebug
is followed by this error:
: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.
现在有很多这样的Ignoring InnerClasses attribute
错误.它们甚至出现在 v4 支持库中的类中,这确实令人困惑.
Now there are dozens of these Ignoring InnerClasses attribute
errors. They even occur for classes in the v4 support library, which is truly perplexing.
最后,这些错误以一个新语句结束:
Finally, these errors end with a new statement:
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)
我已经查阅了以下链接:
I have already consulted the following links:
2. 编译期间忽略 InnerClasses 属性"警告输出是什么?强>.
我不确定它们是否适用于我的情况.我什至无法运行这个项目.我已将 IDE 更新为 SDK Tools 22.0.1 并修改了 build.gradle
文件中的 buildToolsVersion
标记,但无济于事.有人可以指导我如何处理这个错误吗?我们将不胜感激.
I'm not sure they apply to my situation. I'm not even able to run the project. I've updated my IDE to SDK Tools 22.0.1 and modified the buildToolsVersion
tag in my build.gradle
file, but to no avail. Can someone please guide me how to deal with this error ? All help will be appreciated.
哦,这是我的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')
}
请帮助!!!
推荐答案
因为它报告:bad class file magic (cafebabe) or version (0034.0000)
你应该检查你是否正在编译您尝试在运行时使用的相同 Java 版本.如果您使用的是 gradle,您应该在 build.gradle 文件中使用以下或类似的条目:
Because it is reporting: bad class file magic (cafebabe) or version (0034.0000)
you should check if you are compiling with the same java version that you are trying to use at runtime.
If you are using gradle you should use the following or similar entries in your build.gradle file:
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
使用此链接了解更多 gradle 详细信息.
Use this link for more gradle details.
在 Android Studio 中,从 File ->项目结构 ->SDK 位置 ->JDK 位置
您应该使用 jdk 1.7,而不是在 Project level
设置上进行中继.有关类似的 Android Studio 问题,请参阅此链接.
In Android Studio, from File -> Project Structure -> SDK Location -> JDK Location
you should use the jdk 1.7 and not relay on the Project level
setting. See this link for a similar Android Studio question.
这篇关于Android Studio 意外的顶级例外:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!