【问题标题】:Inconsistent behavior when compiling Android apps编译 Android 应用程序时的行为不一致
【发布时间】:2017-04-18 02:26:18
【问题描述】:

我正在研究两个 Android 应用程序 - 一个是我不久前创建的,另一个是我现在正在制作的。当我尝试编译新的时,我收到一个错误“错误:任务':app:compileDebugJavaWithJavac'的执行失败。 compileSdkVersion 'android-25' 需要 JDK 1.8 或更高版本才能编译。”旧应用程序没有出现此错误。为什么会有差异?

新应用的 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'
}

旧应用的 gradle 文件: 应用插件:'com.android.application'

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')
}

在这两种情况下,如果我转到文件 > 项目结构,我会看到它指向相同的 JDK 1.7 路径。

我能看到的最大区别是新应用程序使用的是更新版本的 Gradle 和 Gradle 包装器...我为了解决另一个问题而对其进行了更改(请参阅Why "This app has been built with an incorrect configuration" error occured in some phones?)但我本来希望编译失败更多是在 javac 级别,而不是构建管理器级别。

【问题讨论】:

  • 如果文件 > 项目结构 > JDK 位置指向您的 JDK 1.8 目录,请检查 AndroidStudio。
  • 谢谢,但根据我的问题,它指向我的 JDK 1.7 目录 - 用于工作和非工作项目

标签: android android-studio gradle android-gradle-plugin


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2021-11-01
    相关资源
    最近更新 更多