java 即使升级了 gradle 插件,gradle 项目同步也失败了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47658459/
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-11-03 09:43:47  来源:igfitidea点击:

gradle project sync failed even after upgrading gradle plugin

javaandroid

提问by tsk

Gradle project sync failed and did not get answers from other related questions. Here are the details of my situation.

Gradle 项目同步失败,没有从其他相关问题中得到答案。这是我的情况的详细信息。

Initial sync attempt yielded the following error message:

初始同步尝试产生以下错误消息:

Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

I have Android Studio 3.0. The build.gradle file includes the following dependency:

我有 Android Studio 3.0。build.gradle 文件包含以下依赖项:

classpath 'com.android.tools.build:gradle-experimental:0.2.1'

  The gradle-wrapper.properties file includes the following distribution URL:

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

According to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradleI need to make some changes.
First, update the Gradle version for Android Studio 3.0 in gradle-wrapper.properties:

根据https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle我需要做一些改变。
首先,在 gradle-wrapper.properties 中更新 Android Studio 3.0 的 Gradle 版本:

distributionUrl=\ ? https://services.gradle.org/distributions/gradle-4.1-all.zip (I believe the backslash right after the equal sign is an error and did not make that change.)

分布网址=\ ? https://services.gradle.org/distributions/gradle-4.1-all.zip(我相信等号后面的反斜杠是一个错误,并没有做出改变。)

Second, add the following buildscript repository to build.gradle:

其次,将以下 buildscript 存储库添加到 build.gradle:

google()

谷歌()

Third, change the build.gradle dependency:

第三,更改 build.gradle 依赖项:

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

类路径 'com.android.tools.build:gradle:3.0.1'

The second and third changes apply the latest version of the Android plug-in.

第二个和第三个更改适用于最新版本的 Android 插件。

When I try to sync after these changes it fails again with the following new error:

当我在这些更改后尝试同步时,它再次失败并出现以下新错误:

Plugin with id 'com.android.model.application' not found.

未找到 ID 为“com.android.model.application”的插件。

The error refers to the first line of build.gradle:

错误是指build.gradle的第一行:

apply plugin: 'com.android.model.application'

应用插件:'com.android.model.application'

What is happening and why? I recently added NDK to Android Studio. The project I'm trying to sync includes C code. I'm not completely certain I added NDK correctly. I wonder if that could be part of the problem.

发生了什么,为什么?我最近将 NDK 添加到 Android Studio。我尝试同步的项目包括 C 代码。我不完全确定我是否正确添加了 NDK。我想知道这是否可能是问题的一部分。

回答by ??? ???? ????

First, the gradle-wrapper.propertiesis incorrect. You must include \in it. It should be something like this:

首先,gradle-wrapper.properties是不正确的。你必须包括\在其中。它应该是这样的:

#Sat Jun 17 17:47:18 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Then, add the experimental classpath to project build.gradle. Something like this:

然后,将实验类路径添加到项目 build.gradle。像这样的东西:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Check the Experimental Plugin User Guidefor details.

查看实验插件用户指南了解详细信息。

回答by Jignesh Goyani

Go to your build.gradle version or update it

转到您的 build.gradle 版本或更新它

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

回答by clauub

You should change you dependenciesclasspath

你应该改变你dependenciesclasspath

All steps are here :

所有步骤都在这里:

  • Open build.gradle and change the gradle version to the recommended version:
    classpath 'com.android.tools.build:gradle:1.3.0'to
    classpath 'com.android.tools.build:gradle:2.3.2'
  • Hit 'Try Again'
  • In the messages box it'll say 'Fix Gradle Wrapper and re-import project'Click that, since the minimum gradle version is 3.3
  • A new error will popup and say The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0- Hit Update Build Tools version and sync project
  • A window may popup that says Android Gradle Plugin Update recommended, just update from there.
  • 打开 build.gradle 并将 gradle 版本更改为推荐版本:
    classpath 'com.android.tools.build:gradle:1.3.0'to
    classpath 'com.android.tools.build:gradle:2.3.2'
  • 'Try Again'
  • 在消息框中,它会说'Fix Gradle Wrapper and re-import project'Click that,因为最低 gradle 版本是3.3
  • 将弹出一个新错误并说The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0- HitUpdate Build Tools version and sync project
  • 可能会弹出一个窗口,上面写着Android Gradle Plugin Update recommended,只需从那里更新。

Now the project should be runnable now on any of your android virtual devices.

现在该项目应该可以在您的任何 android 虚拟设备上运行了。

回答by danangmr