Android Studio UNEXPECTED TOP-LEVEL EXCEPTION:

落爺英雄遲暮 提交于 2019-12-01 08:55:00
dan

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

Use this link for more gradle details.

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.

Skizo-ozᴉʞS

UNEXPECTED TOP-LEVEL EXCEPTION means that you are getting included twice any .jar.

As @Akhil said you should exclude support-v4 because I guess it's the main problem, but if @Akhil answer didn't help you try it out this method.

compile (':xyzSDK') {
    exclude group: 'com.android.support', module: 'support-v4'
}

Have you tried to delete this line?

compile 'com.android.support:appcompat-v7:22.1.0'

Maybe :xyzSDK allready has appcompat-v7:22+..

I give you there a good answer by @CommonsWare to make a gradle report to see what's the problem.

I'm working for your answer, so if I find something interessant I'll be updating my answer.

Once you've done this you must Build -> Rebuild project

Also as I saw on @dan answer... I let you there a possible answer.

Instead of 1.7 as dan said try to :

compileOptions {

    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

Otherwise you can check it manually going to File > Project Structure or Ctrl+Alt+Shift+S and then on the JDK location see what are you using and if you are using 1.8 change to your 1.7 SDK path

And btw I think that I've read that you have asked if you could use JAVA 8 for Android instead of JAVA 7 if i'm not wrong.... and yes you could use JDK 8, but only if you also use gradle-retrolamba like says on this question..

It seems your libs folder & library project xyzSDK contains same library, which is causing issues while converting to dex

You can try to identify such library and remove it from one place. Or excluding it like this

compile project(':xyzSDK'){
      exclude module: 'support-v4'
    }

I have taken example of support-v4, as i have faced similar issues due to this one previously.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!