2017-04-18 22 views
0

我看到兩個Android應用程序 - 一個是我創建的,另一個是我現在創建的。當我嘗試編譯新文件時,出現錯誤「Error:Execution failed for task':app:compileDebugJavaWithJavac'。 compileSdkVersion'android-25'需要JDK 1.8或更高版本才能編譯。舊的應用程序沒有出現此錯誤。爲什麼區別?編譯Android應用程序時行爲不一致

新應用程序的文件的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級別,而不是構建管理器級別。

+0

如果文件>項目結構> JDK位置指向您的JDK 1.8目錄,請檢查AndroidStudio。 –

+0

謝謝,但根據我的問題,它指向我的JDK 1.7目錄 - 對於正在運行的項目和非正在運行的項目 – joelt

回答

0

它看起來像是其實是gradle wrapper的原因。如果我採用不同的方法來解決我的初始問題,並將修改回滾到使用v2.8的包裝,則該項目將進行編譯。