2017-08-04 43 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' 
    }