Java 找不到 com.android.tools.build:gradle:2.2.2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40826935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:56:10  来源:igfitidea点击:

Could not find com.android.tools.build:gradle:2.2.2

javaandroid-studiogradlelibgdx

提问by WVrock

A friend of mine copy pasted a libgdx project folder on his pc and sent the project to me(through google drive). We are both using Android Studio. I downloaded and imported the project and it is working properly on the emulator. However it is not working on the desktop. On his pc, it works both in desktop and in the emulator.

我的一个朋友在他的电脑上粘贴了一个 libgdx 项目文件夹并将该项目发送给我(通过谷歌驱动器)。我们都在使用 Android Studio。我下载并导入了该项目,它在模拟器上正常工作。但是它在桌面上不起作用。在他的 PC 上,它可以在桌面和模拟器中运行。

When I try to run it in the desktop, Android Studio gives me this error message:

当我尝试在桌面上运行它时,Android Studio 给了我这个错误信息:

Error:Gradle: A problem occurred configuring root project 'bouncerGDX - Copy'.

> Could not resolve all dependencies for configuration ':classpath'.

> Could not find com.android.tools.build:gradle:2.2.2.
 Searched in the following locations:

https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom

https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.jar

https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom

https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.jar
 Required by:
     :bouncerGDX - Copy:unspecified

How can I fix this? I have no experience with Gradle.

我怎样才能解决这个问题?我没有使用 Gradle 的经验。

采纳答案by exenza

UPD:

更新:

It seems can't resolve com.android.tools.build:gradle:2.2.2dependency for the classpath.

似乎无法解析类路径的com.android.tools.build:gradle:2.2.2依赖项。

For me, adding the jcenter to build.gradleresolves the issue:

对我来说,将 jcenter 添加到build.gradle解决了这个问题:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
}

or, alternatively, the line in build.gradle

或者,build.gradle 中的行

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

can be changed to

可以改为

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

^^^ this version exist in repo1.maven.org

^^^ 这个版本存在于repo1.maven.org

WRONG SUGGESTION:

错误的建议:

Resolve all dependencies by running gradle task (can be done from Android Studio's terminal):

通过运行 gradle 任务解决所有依赖项(可以从 Android Studio 的终端完成):

For Linux:

对于 Linux:

./gradlew buildDependents

For Windows:

对于 Windows:

gradlew.bat buildDependents

Also, this commands might also help later

此外,此命令稍后也可能有所帮助

Linux:

Linux:

./gradlew cleanIdea idea

Windows:

视窗:

gradlew.bat cleanIdea idea

This is the reference to libgdx How-to-setup-development-envinstruction

这是对 libgdx How-to-setup-development-env指令的参考

回答by Max Droid

Seems like you hav dependency on the library project bouncerGDXYou can open build.gradle of that project and change gradle version which is available with you. e.g.

似乎您依赖于库项目bouncerGDX您可以打开该项目的 build.gradle 并更改可用的 gradle 版本。例如

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

回答by user2576737

My fix for the same error was to configure Android Studio for the proxy I'm stuck behind.

我对相同错误的修复是为我被卡在后面的代理配置 Android Studio。

Android Studio + Gradle did not assume system proxy settings, at least not on my copy of macOS. Set your proxy settings in Preferences > Appearance & Behavior > System Settings > HTTP Proxy, save them and restart Android Studio. It then prompted me to set Gradle's proxy settings to match Android Studio's. Once I did this, no more error.

Android Studio + Gradle 没有假设系统代理设置,至少在我的 macOS 副本上没有。在 Preferences > Appearance & Behavior > System Settings > HTTP Proxy 中设置您的代理设置,保存并重启 Android Studio。然后它提示我设置 Gradle 的代理设置以匹配 Android Studio 的。一旦我这样做了,就不会再有错误了。

回答by Jyoti Prakash Rai

I was getting the same issue after updating Android Studio 2.2.2 to 2.3.1

将 Android Studio 2.2.2 更新到 2.3.1 后,我遇到了同样的问题

   Could not find com.android.tools.build:gradle:2.2.2.

Solution:

解决方案:

Open the gradle location and make changes in build.gradle accordingly(module and project both)

打开gradle位置并相应地在build.gradle中进行更改(模块和项目)

I replaced

我换了

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

with

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

And gradle build successfully :-)

并且gradle构建成功:-)

gradle location

gradle 位置

回答by CodeNinja

Adding the maven url solved the issue for me.

添加 Maven url 为我解决了这个问题。

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

回答by Russo

[Solution For Android 2.3.1 built in 2017 April]

【2017年4月内置Android 2.3.1解决方案】

In gradle.build(Project) Add missing repositories mavenLocal() and jcenter() To buildscript { repositories { }}

在 gradle.build(Project) 中添加缺失的 repositories mavenLocal() 和 jcenter() 到 buildscript { repositories { }}

Notice there are TWO gradle.build files!! Pick the right one.

注意有两个 gradle.build 文件!!选择正确的。

回答by Waqleh

In my case I was updating Gradleas Android Studiorecommended enter image description here

就我而言,我正在按照Android Studio 的建议 更新Gradle在此处输入图片说明

Solution:When you import the project make sure not to update Gradle (click "Don't remind me again for this project") and it should work.

解决方案:当您导入项目时,请确保不要更新 Gradle(单击“此项目不再提醒我”),它应该可以工作。

回答by Vrushali Raut

Add this in your build.gradle file

将此添加到您的 build.gradle 文件中

Note: Use latest gradle version.

注意:使用最新的 gradle 版本。

回答by Glendian

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
}
}

add google() below jcenter(),this works for me

在 jcenter() 下面添加 google(),这对我有用