【问题标题】:Receiving a build error when upgrading to gradle 3.3 and android build tools 2.3.0升级到 gradle 3.3 和 android build tools 2.3.0 时收到构建错误
【发布时间】:2017-03-03 05:02:12
【问题描述】:

我刚刚更新了构建文件

从 2.14.1 升级到 3.3 从 2.2.3 到 2.3.0 的 Android 插件

我收到以下错误。似乎是一些第三方插件问题。任何人都可以阐明它吗?我在更改日志中找不到与此更改相关的任何内容。

配置项目 ':apis' 时出现问题。

未能通知项目评估侦听器。

SDK 中不再包含“android”命令。任何参考 应该删除它(例如通过第三方插件)。

引发错误的构建文件如下所示

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
apply plugin: 'android-apt'

android {
  compileSdkVersion Integer.parseInt(ANDROID_SDK_VERSION)
  buildToolsVersion ANDROID_BUILD_TOOLS_VERSION

  // Legacy apache network stack
  useLibrary 'org.apache.http.legacy'

  defaultConfig {
    minSdkVersion Integer.parseInt(ANDROID_MIN_SDK_VERSION)
    targetSdkVersion Integer.parseInt(ANDROID_SDK_VERSION)
    consumerProguardFiles 'proguard-rules.pro'
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }

  packagingOptions {
    exclude 'LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
  }

  lintOptions {
    abortOnError false
  }
}

...

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

    android-apt 已被弃用,根据migration guide

    从 Android Gradle 插件版本 2.2 开始,之前由 android-apt 提供的所有功能现在都可以在 Android 插件中使用。

    您可以删除 android-apt 并按照迁移指南获取等效功能。

    同样,根据sdk-manager-plugin page:

    此插件已弃用,不再开发。工具和依赖项是 automatically downloaded,使用 Android Gradle 插件的 2.2.0 版或更高版本。

    所以它也可以被删除。

    【讨论】:

      【解决方案2】:

      想总结一下我们升级需要什么:

      1. 升级到 gradle 3.3 和 android build tools 2.3.0

        -classpath 'com.android.tools.build:gradle:2.2.3'
        +classpath 'com.android.tools.build:gradle:2.3.0'
        

        -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
        +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
        

        这些应该在您升级时由 Android Studio 自动完成。

      2. 按照@ian 的建议删除android-aptsdk-manager-plugin

        -classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        

        -apply plugin: 'android-sdk-manager'
        -apply plugin: 'com.neenbedankt.android-apt'
        

        这些插件已被弃用,在较新版本的 gradle 中不再需要。

      3. 在 app/build.gradle 文件中更改构建工具版本号:

        -  buildToolsVersion "23.0.3"
        +  buildToolsVersion '25.0.0'
        
      4. 在 gradle 文件中搜索所有 apt 并替换为 annotationProcessor。例如,我们正在使用 AutoValue 和 Parceler,我们必须这样做:

        -  apt "com.ryanharter.auto.value:auto-value-gson:$autoValueGsonVersion"
        +  annotationProcessor "com.ryanharter.auto.value:auto-value-gson:$autoValueGsonVersion"
        

        -  apt "org.parceler:parceler:$parcelerVersion"
        +  annotationProcessor "org.parceler:parceler:$parcelerVersion"
        
      5. 最后,这也很重要,清理并重建。

      【讨论】:

        猜你喜欢
        • 2017-08-02
        • 2018-06-28
        • 2017-09-01
        • 2016-02-05
        • 1970-01-01
        • 1970-01-01
        • 2017-10-25
        • 2013-07-12
        • 1970-01-01
        相关资源
        最近更新 更多