首页 文章

即使在升级gradle插件后,gradle项目同步仍然失败

提问于
浏览
1

Gradle项目同步失败,没有得到其他相关问题的答案 . 以下是我的情况详情 .

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

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.

我有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

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

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

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

谷歌()

Third ,更改build.gradle依赖项:

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

第二次和第三次更改将应用最新版本的Android插件 .

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

没有找到id为'com.android.model.application'的插件 .

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

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

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

4 回答

  • 2

    首先, 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
    

    然后,将实验类路径添加到项目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()
        }
    }
    

    有关详细信息,请查看Experimental Plugin User Guide .

  • 2

    Go to your build.gradle version or update it

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

    你应该改变你 dependencies classpath

    All steps are here :

    • 打开build.gradle并将gradle版本更改为推荐版本:
      classpath 'com.android.tools.build:gradle:1.3.0'
      classpath 'com.android.tools.build:gradle:2.3.2'

    • 点击 'Try Again'

    • 在消息框中它会说 'Fix Gradle Wrapper and re-import project' 点击它,因为最小的gradle版本是 3.3

    • 会弹出一个新错误并说 The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0 - 点击 Update Build Tools version and sync project

    • 可能会弹出一个窗口,显示 Android Gradle Plugin Update recommended ,只是从那里更新 .

    现在,项目应该可以在任何Android虚拟设备上运行 .

相关问题