我想为Android Wear创建一个应用程序。在IntelliJ IDEA 2016.2.1中,我转到文件 - >新 - >项目并选择Android项目。我只检查“磨损”框并制作最小的SDK“N:Android API 23,N预览(预览)”。
我创建了一个运行“Android N,API 23”的Android Wear模拟器。
当我运行MainActivity时,我收到以下错误:
Error:Exception in thread "main" 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: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 '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
当我去File - >项目设置,在“项目”下,Project SDK是“Android API 23,N预览平台”。在“模块”下,应用程序模块SDK和WearApplicationTest模块都是“Project SDK(Android API 23,N预览平台)”。
在平台设置下 - > SDK我有Java 1.8 SDK,具有正确的JDK主路径“/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home”。我还有Java 1.7 SDK,其中包含正确的JDK主路径“/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home”。
此外,我还拥有“Android API 23,N预览平台”SDK,其构建目标为“Android API 23,N预览(预览)”和1.8的Java SDK。我还有“Android API 24 Platform”SDK,其构建目标是“Android API 24”和Java SDK 1.8。最后我有“Android API 23平台”SDK,其构建目标为“Android API 23”,Java SDK为1.7。
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-N'
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "****.wearapplicationtest"
minSdkVersion 'N'
targetSdkVersion 'N'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.4.0'
compile 'com.google.android.gms:play-services-wearable:9.2.1'
}
答案 0 :(得分:1)
尝试使用SDK Manager将您的Android sdks和工具更新到最新版本,并在build.gradle
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "****.wearapplicationtest"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.4.0'
compile 'com.google.android.gms:play-services-wearable:9.2.1'
}