2017-08-04 39 views
3

這是我的android gradle文件。我遇到了不包含該方法的錯誤android gradle插件(例如,在1.1.0中添加了'testcompile')。我該如何解決這個問題。如何使用「classpath」修復build.gradle錯誤com.android.tools.build:gradle:2.3.3'「

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion 25 
    buildToolsVersion "26.0.1" 
    defaultConfig { 
     applicationId "com.xxx.xxxx" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 
repositories { 
    mavenCentral() 
    jcenter() 
} 

dependencies { 
    compile 'com.facebook.android:facebook-android-sdk:[4,5)' 
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
    classpath 'com.android.tools.build:gradle:2.3.3' 
    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:design:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' 
    testCompile group: 'junit', name: 'junit', version: '4.+' 
    compile 'com.android.support.test:runner:0.5' 
} 

錯誤

enter image description here

回答

0

在你dependencies塊,你必須刪除此行

classpath 'com.android.tools.build:gradle:2.3.3' 

此行應在buildscript塊中使用,像:

buildscript { 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.3' 
    } 
} 
+0

它沒有w ^掃。根據您的建議進行更改後 –

+0

您應該將build.gradle發佈到根文件夾中。 –

0

從那裏刪除classpath 'com.android.tools.build:gradle:2.3.3'並將其添加到您的頂級build.gradle文件。

buildscript { 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.3' 
    } 
} 
+0

它沒有工作。根據您的建議進行更改後 –

1

修正後現在構建。 gradle看起來像這樣,現在我把這個錯誤當作「Error:(20,0)Gradle DSL method not found:'classpath()' 可能的原因:

  • 項目'WeatherApp'可能使用Android Gradle版本不包含該方法的插件(例如,在1.1.0中添加了'testCompile') 將插件升級到版本2.3.3並同步項目
  • 項目'WeatherApp'可能使用的Gradle版本包含下面的方法。 打開搖籃封裝文件
  • 構建文件可能丟失一個搖籃插件。 應用搖籃插件
  • apply plugin: 'com.android.application' 
    
    android { 
        compileSdkVersion 25 
        buildToolsVersion "26.0.1" 
        defaultConfig { 
         applicationId "com.xx.xxxxx" 
         minSdkVersion 15 
         targetSdkVersion 25 
         versionCode 1 
         versionName "1.0" 
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
        } 
        buildTypes { 
         release { 
          minifyEnabled false 
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
         } 
         dependencies { 
          classpath 'com.android.tools.build:gradle:2.3.3' 
         } 
        } 
    } 
    repositories { 
        mavenCentral() 
        jcenter() 
    } 
    dependencies { 
        compile 'com.facebook.android:facebook-android-sdk:[4,5)' 
        compile 'com.google.android.gms:play-services-auth:9.2.1' 
        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:design:25.3.1' 
        compile 'com.android.support.constraint:constraint-layout:1.0.2' 
        compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' 
        testCompile group: 'junit', name: 'junit', version: '4.+' 
        compile 'com.android.support.test:runner:0.5' 
    }