编译Android应用程序时行为不一致

编译Android应用程序时行为不一致,android,android-studio,gradle,android-gradle-plugin,Android,Android Studio,Gradle,Android Gradle Plugin,我有两个Android应用程序,一个是我不久前创建的,另一个是我现在正在制作的。当我尝试编译新任务时,我得到一个错误“error:executionfailedfortask”:app:compileDebugJavaWithJavac。 CompileSDK版本“android-25”需要JDK 1.8或更高版本才能编译。“我在旧应用程序中没有遇到此错误。为什么不同 新应用程序的渐变文件: 应用插件:“com.android.application” android { compile

我有两个Android应用程序,一个是我不久前创建的,另一个是我现在正在制作的。当我尝试编译新任务时,我得到一个错误“error:executionfailedfortask”:app:compileDebugJavaWithJavac。 CompileSDK版本“android-25”需要JDK 1.8或更高版本才能编译。“我在旧应用程序中没有遇到此错误。为什么不同

新应用程序的渐变文件: 应用插件:“com.android.application”

android {
    compileSdkVersion 25
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.jtriemstra.forceconnectfromphone"
        minSdkVersion 19
        targetSdkVersion 21
        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
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.0.0'
}
android {
    compileSdkVersion 25
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.jtriemstra.timeswitch"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'commons-codec:commons-codec:1.10'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile files('libs/nmdp_speech_kit.jar')
}
旧应用程序的gradle文件: 应用插件:“com.android.application”

android {
    compileSdkVersion 25
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.jtriemstra.forceconnectfromphone"
        minSdkVersion 19
        targetSdkVersion 21
        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
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.0.0'
}
android {
    compileSdkVersion 25
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.jtriemstra.timeswitch"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'commons-codec:commons-codec:1.10'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile files('libs/nmdp_speech_kit.jar')
}
在这两种情况下,如果我转到File>projectstructure,我会看到它指向相同的JDK1.7路径


我所能看到的最大区别是,新应用程序使用的是较新版本的Gradle和Gradle包装器…我为了解决另一个问题(请参阅)而对其进行了更改,但我原以为编译失败更多地发生在javac级别,而不是构建管理器级别。

看起来原因实际上是Gradle包装器。如果我采用不同的方法来解决初始问题,并回滚对包装器的更改以使用v2.8,则项目将编译。

如果文件>项目结构>JDK位置指向您的JDK 1.8目录,请签入AndroidStudio。谢谢,但根据我的问题,它指向了我的JDK1.7目录——适用于工作项目和非工作项目