简体   繁体   English

将旧的Eclipse项目导入Android Studio会导致Gradle 3.3.1错误

[英]Importing old Eclipse Project into Android Studio gives Gradle 3.3.1 error

After doing several searches, I'm not sure which of the handful of methods to follow to fix this. 经过几次搜索后,我不确定要遵循哪些方法来解决此问题。

Importing an old (3, 4 years now) Eclipse project into the latest Android Studio, using all of the defaults on import. 使用导入时的所有默认值,将旧的Eclipse项目(至今已有3、4年)导入到最新的Android Studio中。 After import, the summary says it replaced two JARs with dependencies: 导入后,摘要表示已用依赖项替换了两个JAR:

android-support-v4.jar => com.android.support:support-v4:22.2.1
android-support-v7-appcompat.jar => com.android.support:appcompat-v7:22.2.1

and one library with a dependency: 和一个具有依赖性的库:

google-play-services_lib => [com.google.android.gms:play-services:+]

Now, the project won't build, as it immediately gives this error: 现在,该项目将无法生成,因为它立即产生此错误:

ERROR: Could not find com.android.tools.build:gradle:3.3.1.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.3.1/gradle-3.3.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.3.1/gradle-3.3.1.jar

Required by:
project :

Add Google Maven repository and sync project
Open File
Enable embedded Maven repository and sync project

Seems odd that I would run into this issue out of the blue on a fresh conversion of an Eclipse project. 似乎很奇怪,在重新转换Eclipse项目时,我会突然遇到这个问题。 The two URLs (jcenter.buntray.com) when hit Do give back some JSON that pretty much says resource doesn't exist. 点击Do时的两个URL(jcenter.buntray.com)会返回一些JSON,该JSON几乎表明资源不存在。

What did I do wrong on the import? 我在导入上做错了什么? Or did I not install something in the SDK properly? 还是我没有在SDK中正确安装某些软件? Unlike the other question, AS is already telling to refer gradle to jcenter and not maven. 与其他问题不同,AS已经在告诉将gradle引用到jcenter而不是maven。

Ah - I left out the following - After clicking on the 'Add Google Maven' and accepting the 'preview', gradle does some processing, and reports that my gradle version is too low (minimum supported is 4.10, my version is 4.8) and gives me an option to update. 嗯-我遗漏了以下内容-单击“添加Google Maven”并接受“预览”后,gradle进行了一些处理,并报告我的gradle版本太低(最低支持为4.10,我的版本为4.8)并且给我一个更新选项。

After doing an update, it seems to start building, but then returns me to the first error above, about not finding 3.3.1. 完成更新后,它似乎开始构建,但随后使我返回到上面的第一个错误,即未找到3.3.1。 (Like the project file is being reset back to import state. (就像将项目文件重置回导入状态一样。

Have not done any manual file saves between these steps. 这些步骤之间没有做任何手动文件保存。

Check the official documentation : 检查官方文档

Could not find com.android.tools.build:gradle:3.3.1. 找不到com.android.tools.build:gradle:3.3.1。

It happens because you have to add the google() maven repo in your buildscript block in the build.gradle file in the root folder (also called top-level file). 发生这种情况是因为您必须在根文件夹(也称为顶级文件)的build.gradle文件的buildscript块中的google() maven存储库中添加。 It is required for the android gradle plugin 3.0 or higher. android gradle plugin 3.0或更高版本需要它。

buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android Gradle plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
    }
}

To update the version of gradle just edit the gradle/wrapper/gradle-wrapper.properties in the root folder. 要更新gradle的版本,只需在根文件夹中编辑gradle/wrapper/gradle-wrapper.properties

...
distributionUrl = https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM