I am getting the following build error when I try and sync my project:
当我尝试同步我的项目时,我得到如下的构建错误:
Error:(9, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'AlexTest' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
link: Apply Gradle plugin
I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.
我尝试过应用每一个他们链接到我在底部的链接,但同样的问题,所以我得出结论,第一个错误是原因。
Here is the build.gradle file for AlexTest (the project directory):
这是构建。AlexTest的gradle文件(项目目录):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
compile 'com.google.android.gms:play-services:6.1.11'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I think that was the gradle file it was having trouble with. But I'm not sure what method it is referring to.
我想那是它遇到麻烦的等级文件。但我不确定它指的是什么方法。
Also here is the gradle-wrapper.properties which it also referred to:
这里还有一个渐变包装。它还提到的财产:
#Mon Nov 10 01:06:12 PST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
perhaps the gradle version in the distributionUrl needs to match the one in the dependency?
也许分布url中的gradle版本需要与依赖项中的一个匹配?
I also have a build.gradle file in the app directory itself - 1 level lower, though I don't think that is what it was referring to, but here it is:
我也有一个建筑。应用程序目录本身的gradle文件- 1级更低,虽然我不认为这是它所指的,但这里是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.snappiesticker.alextest"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.1.+'
}
5 个解决方案
#1
77
I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.
我尝试过应用每一个他们链接到我在底部的链接,但同样的问题,所以我得出结论,第一个错误是原因。
Correct.
正确的。
Here is the build.gradle file for AlexTest (the project directory):
这是构建。AlexTest的gradle文件(项目目录):
You will notice that this file contains a code comment:
您将注意到该文件包含一个代码注释:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Remove the compile 'com.google.android.gms:play-services:6.1.11'
line from that file. Leave the compile 'com.google.android.gms:play-services:6.1.+'
that you have in the other build.gradle
file.
删除编译'com.google.android.gms:play-services:6.1.11' line从该文件。离开编译com.google.android.gms:游戏服务:6.1。+“你在另一个建筑里。”gradle文件。
The dependencies
closure in buildscript
is for Gradle plugins only. The top-level dependencies
closure, found in the module's build.gradle
file, is for application dependencies.
buildscript中的依赖关系关闭只适用于Gradle插件。在模块的构建中发现的*依赖项闭包。gradle文件,用于应用程序依赖项。
#2
12
Saw reports that the problem occurred for other reasons, but this solved for me.
看到报告说,问题出在其他原因,但这解决了我。
If you carry out any changes in the Project Structure (Android Studio) and press OK, Gradle will be synchronized, but this type of synchronization, if the dependency block has something like:
如果您在项目结构(Android Studio)中执行任何更改,并按OK, Gradle将被同步,但是这种类型的同步,如果依赖块有类似的东西:
This block will stay this way after synchronization:
此块在同步之后将保持这种方式:
One way to solve the problem is to insert a line break to stay as it was before the synchronization or put a semi-colon between the two statements.
解决这个问题的一种方法是在同步之前插入一个换行符,或者在两个语句之间放入一个分号。
I hope it helps.
我希望它有帮助。
#3
3
Just add foolwoing statement in your dependencies
在依赖项中添加简单的语句。
apply plugin: 'jetty'
应用插件:“码头”
#4
1
Hi everyone for me it was a "couple days consuming job" to make my app run in Android Studio (I migrated from Eclipse and had this problem too ) . Finally I found that very simple way of it .
大家好,对我来说,让我的应用程序运行在Android Studio中是“两三天的工作”(我从Eclipse迁移过来,也有这个问题)。最后,我找到了一种非常简单的方法。
- Create libs folder under src/main/java/ it is App/java/libs in left pane .
- 在src/main/java/ it is App/java/libs在左窗格中创建libs文件夹。
- Copy and paste all your external jars into here.
- 把你所有的外部罐子复制粘贴到这里。
- Goto left pane and right click on your App then click Open Module Settings
- Goto左窗格和右键单击你的应用,然后点击打开模块设置。
- Then Project Structure window will appear .
- 然后将出现项目结构窗口。
- Then move to Dependencies tab . Final Step : Add all your jars located in App/java/libs (You will find them in src/main/java/libs) one by one .
- 然后移动到Dependencies选项卡。最后一步:把你所有的jar放在App/java/libs(你会在src/main/java/libs中找到它们)一个接一个。
That is all Enjoy it.
大家都很喜欢。
#5
#1
77
I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.
我尝试过应用每一个他们链接到我在底部的链接,但同样的问题,所以我得出结论,第一个错误是原因。
Correct.
正确的。
Here is the build.gradle file for AlexTest (the project directory):
这是构建。AlexTest的gradle文件(项目目录):
You will notice that this file contains a code comment:
您将注意到该文件包含一个代码注释:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Remove the compile 'com.google.android.gms:play-services:6.1.11'
line from that file. Leave the compile 'com.google.android.gms:play-services:6.1.+'
that you have in the other build.gradle
file.
删除编译'com.google.android.gms:play-services:6.1.11' line从该文件。离开编译com.google.android.gms:游戏服务:6.1。+“你在另一个建筑里。”gradle文件。
The dependencies
closure in buildscript
is for Gradle plugins only. The top-level dependencies
closure, found in the module's build.gradle
file, is for application dependencies.
buildscript中的依赖关系关闭只适用于Gradle插件。在模块的构建中发现的*依赖项闭包。gradle文件,用于应用程序依赖项。
#2
12
Saw reports that the problem occurred for other reasons, but this solved for me.
看到报告说,问题出在其他原因,但这解决了我。
If you carry out any changes in the Project Structure (Android Studio) and press OK, Gradle will be synchronized, but this type of synchronization, if the dependency block has something like:
如果您在项目结构(Android Studio)中执行任何更改,并按OK, Gradle将被同步,但是这种类型的同步,如果依赖块有类似的东西:
This block will stay this way after synchronization:
此块在同步之后将保持这种方式:
One way to solve the problem is to insert a line break to stay as it was before the synchronization or put a semi-colon between the two statements.
解决这个问题的一种方法是在同步之前插入一个换行符,或者在两个语句之间放入一个分号。
I hope it helps.
我希望它有帮助。
#3
3
Just add foolwoing statement in your dependencies
在依赖项中添加简单的语句。
apply plugin: 'jetty'
应用插件:“码头”
#4
1
Hi everyone for me it was a "couple days consuming job" to make my app run in Android Studio (I migrated from Eclipse and had this problem too ) . Finally I found that very simple way of it .
大家好,对我来说,让我的应用程序运行在Android Studio中是“两三天的工作”(我从Eclipse迁移过来,也有这个问题)。最后,我找到了一种非常简单的方法。
- Create libs folder under src/main/java/ it is App/java/libs in left pane .
- 在src/main/java/ it is App/java/libs在左窗格中创建libs文件夹。
- Copy and paste all your external jars into here.
- 把你所有的外部罐子复制粘贴到这里。
- Goto left pane and right click on your App then click Open Module Settings
- Goto左窗格和右键单击你的应用,然后点击打开模块设置。
- Then Project Structure window will appear .
- 然后将出现项目结构窗口。
- Then move to Dependencies tab . Final Step : Add all your jars located in App/java/libs (You will find them in src/main/java/libs) one by one .
- 然后移动到Dependencies选项卡。最后一步:把你所有的jar放在App/java/libs(你会在src/main/java/libs中找到它们)一个接一个。
That is all Enjoy it.
大家都很喜欢。