有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

升级gradle插件后,java gradle项目同步仍失败

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。建造。gradle文件包含以下依赖项:

classpath 'com.安卓.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.安卓.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle我需要做一些改变
首先,在Gradle wrapper中更新Android Studio 3.0的Gradle版本。属性:

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

第二步,添加以下要构建的buildscript存储库。格雷德尔:

谷歌()

第三个,更改构建。渐变依赖性:

classpath'com。安卓工具。建造:渐变:3.0.1'

第二个和第三个变化适用于最新版本的Android插件

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

id为'com的插件。安卓模型找不到应用程序

该错误涉及构建的第一行。格雷德尔:

应用插件:com。安卓模型申请

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


共 (3) 个答案

  1. # 1 楼答案

    你应该改变你dependencies{}

    所有步骤都在这里:

    • 开放式构建。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-Hit Update Build Tools version and sync project
    • 可能会弹出一个窗口,上面写着Android Gradle Plugin Update recommended,只需从那里更新即可

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

  2. # 2 楼答案

    进入你的身体。升级或更新版本

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
    
  3. # 3 楼答案

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

    然后,将实验类路径添加到项目构建中。格雷德尔。比如:

    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以了解详细信息