我遇到了以下问题:
我正在编写一个使用谷歌地图的应用程序,我想添加这个外部库
https://github.com/route360/r360-java
我想将lib作为.jar文件添加到Android Studio中,所以我使用Java 8编译它(使用Java 7编译不起作用)。
将.jar添加为lib并将其添加到依赖项并运行应用程序后,我收到以下错误消息:
Error:PARSE ERROR:
Error:unsupported class file version 52.0
Error:...while parsing net/motionintelligence/client/Constants.class
Error:1 error; aborting
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 1
经过SO的一些研究后我发现这可能是我使用的错误Java版本的结果,所以我安装了Java 7,将Android Studio JDK更改为Java 7并尝试运行该应用程序。结果如下:
Error:java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
Error: at java.lang.ClassLoader.defineClass1(Native Method)
Error: at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
Error: at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
Error: at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
Error: at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
Error: at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
Error: at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
Error: at java.security.AccessController.doPrivileged(Native Method)
Error: at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
Error: at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
Error: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
Error: at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Error: at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Error:Exception in thread "main"
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1
我尝试在Android API之间切换,但没有来自SO的解决方案。
目前我正在使用API 23 Android 6.0。
这是我的子模块的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
defaultConfig {
applicationId "com.example.jule.bachelorapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile files('libs/r360-java-client-0.0.1.jar')
}
有谁知道如何摆脱这些错误?我真的需要使用该库,所以非常感谢帮助。