Android Studio UNEXPECTED TOP-LEVEL EXCEPTION:

前端 未结 3 818
失恋的感觉
失恋的感觉 2021-01-14 05:04

Today I am faced with a massive error that doesn\'t let me run a sample project on my phone.

When Android Studio is building the project, it first shows the followin

相关标签:
3条回答
  • 2021-01-14 05:13

    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..

    0 讨论(0)
  • 2021-01-14 05:16

    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.

    0 讨论(0)
  • 2021-01-14 05:18

    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.

    0 讨论(0)
提交回复
热议问题