简体   繁体   中英

IntelliJ - Creating an application for Android Wear

I want to create an application for Android Wear. In IntelliJ IDEA 2016.2.1, I go to File -> New -> Project and select Android project. I check only the "Wear" box and make the minimum SDK "N: Android API 23, N preview (Preview)".

I create an Android Wear emulator that runs "Android N, API 23".

When I run the MainActivity I get the following error:

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

When I go to File -> Project Settings, under "Project" the Project SDK is "Android API 23, N preview Platform". Under "Modules" the app Module SDK and the WearApplicationTest Module are both "Project SDK (Android API 23, N preview Platform)".

Under Platform Settings -> SDKs I have the Java 1.8 SDK, with the correct JDK home path "/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home". I also have the Java 1.7 SDK with the correct JDK home path "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home".

Additionally I have the "Android API 23, N preview Platform" SDK which has a build target of "Android API 23, N preview (Preview)" and Java SDK of 1.8. I also have the "Android API 24 Platform" SDK with a build target of "Android API 24" and Java SDK of 1.8. And lastly I have the "Android API 23 Platform" SDK with the build target of "Android API 23" and Java SDK of 1.7.

Here is my 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'
}

Try updating your android sdks and tools to latest version using SDK Manager and changing your references of "N" to 24 in your 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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM