I am trying to use gradle build. It gives me error saying that
我正在尝试使用gradle构建。这给了我错误的说法
Failed to apply plugin [id 'com.android.library'] Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /home/sanjeewa/workspace/Android/UVCCamera/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip
无法应用插件[id'com.android.library'] Gradle 2.2版是必需的。当前版本是2.10。如果使用gradle包装器,请尝试将/home/sanjeewa/workspace/Android/UVCCamera/gradle/wrapper/gradle-wrapper.properties中的distributionUrl编辑为gradle-2.2-all.zip
But my gradle-wrapper.properties includes gradle-2.4-all.zip. I have changed it to gradle-2.2-all.zip Still same problem.
但我的gradle-wrapper.properties包括gradle-2.4-all.zip。我把它改成了gradle-2.2-all.zip还是同样的问题。
When I run gradle -version in terminal Gradle 2.10 shows as version.
当我在终端Gradle 2.10中运行gradle -version时显示为版本。
How to solve that error??
如何解决这个错误?
my build gradle file is
我的构建gradle文件是
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
7 个解决方案
#1
115
- Open
gradle-wrapper.properties
- 打开gradle-wrapper.properties
-
Change this line:
改变这一行:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
同
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
- Go to
build.gradle
(Project: your_app_name) - 转到build.gradle(Project:your_app_name)
-
Change this line
改变这一行
classpath 'com.android.tools.build:gradle:XXX'
to this
对此
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
or
要么
classpath 'com.android.tools.build:gradle:1.5.0'
- Don't click
Sync Now
- 不要单击立即同步
- From menu choose
File -> Invalidate Caches/Restart...
- 从菜单中选择文件 - >无效缓存/重新启动...
- Choose first option:
Invalidate and Restart
- 选择第一个选项:无效并重新启动
Android Studio would restart. After this, it should work normally
Android Studio会重新启动。在此之后,它应该正常工作
Hope it help
希望它有所帮助
#2
39
Current work around is to overrideVersionCheck: In your build.gradle
目前的解决方法是覆盖版本检查:在build.gradle中
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
Check this link for more Details
查看此链接了解更多详情
#3
23
Just Change in build.gradle file
只需更改build.gradle文件即可
classpath 'com.android.tools.build:gradle:1.3.0'
To
至
classpath 'com.android.tools.build:gradle:2.0.0'
-
Now
GoTo
->menu choose File
->Invalidate Caches/Restart
...现在GoTo - >菜单选择File - > Invalidate Caches / Restart ...
-
Choose first option:
Invalidate and Restart
选择第一个选项:无效并重新启动
Android Studio would restart.
Android Studio会重新启动。
After this, it should work normally.
在此之后,它应该正常工作。
#4
10
Based on https://developer.android.com/studio/releases/gradle-plugin.html ...
基于https://developer.android.com/studio/releases/gradle-plugin.html ...
The following table lists which version of Gradle is required for each version of the Android plugin for Gradle. For the best performance, you should use the latest possible version of both Gradle and the Android plugin.
下表列出了Gradle的每个Android插件版本所需的Gradle版本。为获得最佳性能,您应该使用Gradle和Android插件的最新版本。
So, the Plugin version with Required Gradle version should be match.
因此,具有Required Gradle版本的插件版本应该匹配。
#5
1
Use ./gradlew
instead of gradle
to resolve this issue.
使用./gradlew而不是gradle来解决此问题。
#6
1
Here's what I did to fix this:
这是我为解决这个问题所做的事情:
1) Create a new project
1)创建一个新项目
2) open the gradle-wrapper.properties file and copy the distributionUrl to your project e.g.:
2)打开gradle-wrapper.properties文件并将distributionUrl复制到您的项目中,例如:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
3) open the build.gradle (Project) and copy the gradle dependency to your project e.g.:
3)打开build.gradle(Project)并将gradle依赖项复制到你的项目中,例如:
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
4) File --> Invalidate Caches / Restart (I think a re-sync may have sufficed, but didn't try it)
4)文件 - >无效缓存/重启(我认为重新同步可能已经足够,但没有尝试)
5) Delete that project you made (optional)
5)删除你做的项目(可选)
Look, this is a silly way to do things, but Android Studio is free so who am I to complain...
看,这是一种愚蠢的做事方式,但Android Studio是免费的,所以我该抱怨谁...
#7
0
The android studio and Gradle version looks like very bad managed. And there's tons of version in-capability issues. And the error message is mostly clueless. For this particular issue. The closest answer is from "Jitendra Singh". Change the version to:
android studio和Gradle版看起来非常糟糕。并且有大量版本的能力问题。错误信息大多是无能为力的。对于这个特殊问题。最接近的答案来自“Jitendra Singh”。将版本更改为:
classpath 'com.android.tools.build:gradle:2.0.0'
But in my case: Android studio 2.2 RC, I still get another error:
但在我的情况下:Android studio 2.2 RC,我仍然得到另一个错误:
Could not find matching constructor for: com.android.build.gradle.internal.LibraryTaskManager(org.gradle.api.internal.project.DefaultProject_Decorated, com.android.builder.core.AndroidBuilder, android.databinding.tool.DataBindingBuilder, com.android.build.gradle.LibraryExtension_Decorated, com.android.build.gradle.internal.SdkHandler, com.android.build.gradle.internal.DependencyManager, org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry)
So I went to the maven central to find the latest com.android.tools.build:gradle version which is 2.1.3 for now. So after change to
所以我去maven中心找到最新的com.android.tools.build:gradle版本,现在是2.1.3。所以改成之后
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
Solved my problem eventually.
最终解决了我的问题。
#1
115
- Open
gradle-wrapper.properties
- 打开gradle-wrapper.properties
-
Change this line:
改变这一行:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
同
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
- Go to
build.gradle
(Project: your_app_name) - 转到build.gradle(Project:your_app_name)
-
Change this line
改变这一行
classpath 'com.android.tools.build:gradle:XXX'
to this
对此
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
or
要么
classpath 'com.android.tools.build:gradle:1.5.0'
- Don't click
Sync Now
- 不要单击立即同步
- From menu choose
File -> Invalidate Caches/Restart...
- 从菜单中选择文件 - >无效缓存/重新启动...
- Choose first option:
Invalidate and Restart
- 选择第一个选项:无效并重新启动
Android Studio would restart. After this, it should work normally
Android Studio会重新启动。在此之后,它应该正常工作
Hope it help
希望它有所帮助
#2
39
Current work around is to overrideVersionCheck: In your build.gradle
目前的解决方法是覆盖版本检查:在build.gradle中
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
Check this link for more Details
查看此链接了解更多详情
#3
23
Just Change in build.gradle file
只需更改build.gradle文件即可
classpath 'com.android.tools.build:gradle:1.3.0'
To
至
classpath 'com.android.tools.build:gradle:2.0.0'
-
Now
GoTo
->menu choose File
->Invalidate Caches/Restart
...现在GoTo - >菜单选择File - > Invalidate Caches / Restart ...
-
Choose first option:
Invalidate and Restart
选择第一个选项:无效并重新启动
Android Studio would restart.
Android Studio会重新启动。
After this, it should work normally.
在此之后,它应该正常工作。
#4
10
Based on https://developer.android.com/studio/releases/gradle-plugin.html ...
基于https://developer.android.com/studio/releases/gradle-plugin.html ...
The following table lists which version of Gradle is required for each version of the Android plugin for Gradle. For the best performance, you should use the latest possible version of both Gradle and the Android plugin.
下表列出了Gradle的每个Android插件版本所需的Gradle版本。为获得最佳性能,您应该使用Gradle和Android插件的最新版本。
So, the Plugin version with Required Gradle version should be match.
因此,具有Required Gradle版本的插件版本应该匹配。
#5
1
Use ./gradlew
instead of gradle
to resolve this issue.
使用./gradlew而不是gradle来解决此问题。
#6
1
Here's what I did to fix this:
这是我为解决这个问题所做的事情:
1) Create a new project
1)创建一个新项目
2) open the gradle-wrapper.properties file and copy the distributionUrl to your project e.g.:
2)打开gradle-wrapper.properties文件并将distributionUrl复制到您的项目中,例如:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
3) open the build.gradle (Project) and copy the gradle dependency to your project e.g.:
3)打开build.gradle(Project)并将gradle依赖项复制到你的项目中,例如:
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
4) File --> Invalidate Caches / Restart (I think a re-sync may have sufficed, but didn't try it)
4)文件 - >无效缓存/重启(我认为重新同步可能已经足够,但没有尝试)
5) Delete that project you made (optional)
5)删除你做的项目(可选)
Look, this is a silly way to do things, but Android Studio is free so who am I to complain...
看,这是一种愚蠢的做事方式,但Android Studio是免费的,所以我该抱怨谁...
#7
0
The android studio and Gradle version looks like very bad managed. And there's tons of version in-capability issues. And the error message is mostly clueless. For this particular issue. The closest answer is from "Jitendra Singh". Change the version to:
android studio和Gradle版看起来非常糟糕。并且有大量版本的能力问题。错误信息大多是无能为力的。对于这个特殊问题。最接近的答案来自“Jitendra Singh”。将版本更改为:
classpath 'com.android.tools.build:gradle:2.0.0'
But in my case: Android studio 2.2 RC, I still get another error:
但在我的情况下:Android studio 2.2 RC,我仍然得到另一个错误:
Could not find matching constructor for: com.android.build.gradle.internal.LibraryTaskManager(org.gradle.api.internal.project.DefaultProject_Decorated, com.android.builder.core.AndroidBuilder, android.databinding.tool.DataBindingBuilder, com.android.build.gradle.LibraryExtension_Decorated, com.android.build.gradle.internal.SdkHandler, com.android.build.gradle.internal.DependencyManager, org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry)
So I went to the maven central to find the latest com.android.tools.build:gradle version which is 2.1.3 for now. So after change to
所以我去maven中心找到最新的com.android.tools.build:gradle版本,现在是2.1.3。所以改成之后
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
Solved my problem eventually.
最终解决了我的问题。