2017-04-10 74 views
0

我是Android应用程序开发新手。我正在尝试使用TabLayout创建一个Android应用程序,并在build.gradle文件中添加了以下依赖项。Gradle同步失败:无法找到方法compile()参数[com.android.support:appcompat-v7:25.3.1]

dependencies { 
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 'com.android.support:support-v4:25.3.1' 
testCompile 'junit:junit:4.12' 


} 

但上运行的应用程序,我得到如下

Error:(27, 0) Gradle DSL method not found: 'compile()' Possible causes:

  • The project 'MyFirstapp' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 为什么这个问题有什么建议,建立自己的错误。我可以从Android Studio安装插件,但我不知道要安装哪个插件。

    +0

    http://stackoverflow.com/questions/27156428/getting-error-gradle-dsl-method-not-found-compile-when-syncing-build-grad – Steve

    回答

    2

    我猜你正在向错误的build.gradle添加依赖关系。

    试着这样做: 在您第一次的build.gradle这个

    dependencies { 
        classpath 'com.android.tools.build:gradle:2.3.0' 
    } 
    

    更换依赖和替换的build.gradle依赖(模块:APP)与此

    (第2的build.gradle文件)
    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' 
        testCompile 'junit:junit:4.12' 
    } 
    
    +0

    它解决了我的问题。感谢您的帮助 –

    +0

    我有同样的问题。我找不到com.android.support:appcompat-v7:25.3.1。请帮助我:http://i.imgur.com/cqPtiSg.png –

    相关问题