1. 程式人生 > >我的Android進階之旅------>解決Error:Could not find property 'compile' on org.gradle.api.internal.artifacts.

我的Android進階之旅------>解決Error:Could not find property 'compile' on org.gradle.api.internal.artifacts.

1、錯誤描述

剛剛,Android Studio突然編譯不了了,報瞭如下錯誤:

Error:Could not find property 'compile' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@1b3472dc.

如下圖所示:
這裡寫圖片描述

2.解決方法

根據上面的提示,我去打開了build.gradle檔案,發現我的build.gradle檔案不知道被誰弄亂了,其中一段程式碼變成了如下所示:

1、錯誤原因

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //監測記憶體洩漏
    //    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
    //    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
    compile(name: 'common-release', ext: 'aar')
    compile(name: 'sync-release'
, ext: 'aar') // compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.android.support:appcompat-v7:23.3.0'compile 'com.android.support:design:23.3.0'compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0'compile 'com.squareup.retrofit2:retrofit:2.0.0'compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0' compile 'io.reactivex:rxandroid:1.1.0' compile 'com.j256.ormlite:ormlite-core:4.48' compile 'com.j256.ormlite:ormlite-android:4.48' compile 'com.jakewharton:butterknife:7.0.1' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3' testCompile 'junit:junit:4.12' testCompile 'org.powermock:powermock-module-junit4:1.6.4' testCompile 'org.powermock:powermock-api-mockito:1.6.4' testCompile 'org.robolectric:robolectric:3.0' }

如圖所示:

這裡寫圖片描述

2、解決方法

將上面的gradle檔案重新排版,修改為如下所示的程式碼:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //監測記憶體洩漏
    //    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
    //    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
    compile(name: 'common-release', ext: 'aar')
    compile(name: 'sync-release', ext: 'aar')
//  compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
    testCompile 'junit:junit:4.12'
    testCompile 'org.powermock:powermock-module-junit4:1.6.4'
    testCompile 'org.powermock:powermock-api-mockito:1.6.4'
    testCompile 'org.robolectric:robolectric:3.0'
}

如下圖所示:
這裡寫圖片描述

然後重新編譯程式碼,即可正常。

這裡寫圖片描述