我正在查看两个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')
}
在这两种情况下,如果都转到"file">“项目结构”,则会看到它指向相同的JDK 1.7路径。
我能看到的最大区别是,新应用程序正在使用较新版本的Gradle和Gradle包装器...为了解决另一个问题,我进行了更改(请参阅Why "This app has been built with an incorrect configuration" error occured in some phones?),但是我希望编译失败会更多在javac级别,而不是在构建管理器级别。
最佳答案
看起来原因实际上是gradle包装器。如果我采用其他方法来解决最初的问题,然后将更改回滚到包装器以使用v2.8,则将编译项目。
关于android - 编译Android应用时的行为不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43462579/