1. The first time I encountered this error was added in build.gradle
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
The reason is that Android now only supports language features up to jdk7
see
Which JDK version (Language Level) is required for Android Studio?
Is it possible to use Java 8 for Android development?
The solution is also very simple: remove this paragraph directly, or reduce the version to 1.7
sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7
see
UNEXPECTED TOP-LEVEL EXCEPTION adding new Module to Android Studio project
If you must use the new features of java8, you can refer to an open source project on github
Of course, the error may also be resolved at some stage when Google decides to support jdk8
2. There may also be a jar conflict
For example, both v4 and v7 android support are set in the dependency
Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION
For example, Umeng's message push jar conflicts with Alipay SDK
Conflict between push components and Alipay SDK
For example, Umeng's social component (sharing) SDK conflicts with WeChat's native SDK
Unable to execute dex: Multiple dex files define
(Note: It should be either SocialSDK_WeiXin_1.jar or libammsdk.jar now)