1. 程式人生 > >Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'.

Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'.

警告是這樣的:

**Warning:Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’.It will be removed at the end of 2018**

講的是 :

**警告:配置' compile '已過時,已被' implementation '取代。將在2018年***去除掉這個**

解決辦法:

例如我們以前的程式碼是這樣的:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-core-ui:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
}

改寫後的程式碼:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-core-ui:25.3.1'
    implementation 'com.android.support:design:25.3.1'
    testImplementation 'junit:junit:4.12'
}

改的原則:

compile  改成  implementation 
androidTestCompile  改成  androidTestImplementation 
testCompile  改成  testImplementation

總之就是把看到有compile  改成  implementation 就行了

對於他們兩個的區別,其實我覺得區別不太大感覺就是Google把他優化了一下

compile與implemention 的區別

compile:可以傳遞依賴和引用,但是編譯時間長於implementation

implementation:

不可傳遞依賴引用,比如B依賴A,C依賴B,但是C卻不能依賴A。所以編譯時間更短。

但是對於他們的用處還是一樣的,沒有做什麼改變,對於api代替compile,他們功能相同。