首页 > 解决方案 > 将 android studio 更新到 3.4 版后 Gradle 失败

问题描述

我今天更新了 Android Studio,我的颤振项目不再工作。Gradle 失败并显示以下消息:


* Error running Gradle:
ProcessException: Process "C:\Projects\firebase_setup_app\android\gradlew.bat" exited abnormally:

> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
         *********************************************************
WARNING: This version of firebase_auth will break your Android build if it or its dependencies aren't compatible with AndroidX.
         See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
         This warning prints for all Android build failures. The real root cause of the error may be unrelated.
         *********************************************************
  Command: C:\Projects\firebase_setup_app\android\gradlew.bat app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.

我已经尝试在最新版本的工作室中制作一个新的颤振项目,并且构建良好。

这个问题似乎与我在我的项目中使用 google play 服务和 firebase 的事实有关。根据 IDE 的提示,我将 google 服务更新到最新版本(4.2.0)并升级到 3.4.0

我在 android/app/build.gradle 中将已编译的SDKVersion 从 27 更新为 28

我已将 android/gradle/gradle-wrapper.properties 中的 gradle 版本从 4.10.2 更新到 5.1.1,因为存在不兼容问题并提示我进行更新。

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

我已经完成了重构>迁移到 AndroidX... 并包括:

android.useAndroidX=true
android.enableJetifier=true

在 gradle.properties 文件中

我尝试通过“文件>使缓存无效并重新启动...”清除缓存

我已经尝试过 flutter clean 和 flutter doctor -v ,但没有显示任何问题:

C:\Projects\firebase_setup_app>flutter clean
Deleting 'build\'.
Deleting 'C:\Projects\firebase_setup_app\.dart_tool\'.

C:\Projects\firebase_setup_app>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 6.3.9600], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.4)
[√] IntelliJ IDEA Community Edition (version 2018.3)
[√] Connected device (1 available)

• No issues found!

C:\Projects\firebase_setup_app>flutter doctor -v
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 6.3.9600], locale en-GB)
    • Flutter version 1.2.1 at C:\src\flutter\flutter_windows_v1.0.0-stable\flutter
    • Framework revision 8661d8aecd (10 weeks ago), 2019-02-14 19:19:53 -0800
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin version 34.0.2
    • Dart plugin version 183.5901
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] IntelliJ IDEA Community Edition (version 2018.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.3
    • Flutter plugin version 31.3.4
    • Dart plugin version 183.5153.38

[√] Connected device (1 available)
    • SM G930F • ce0616069dbace2f03 • android-arm64 • Android 8.0.0 (API 26)

• No issues found!

我还更新了 android/build.gradle 依赖项:

   dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        //classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
    }

android/app/build.gradle 依赖如下:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

apply plugin: 'com.google.gms.google-services'

我的 pubspec.yaml 包括以下插件:

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  google_sign_in: ^4.0.1+3
  firebase_auth: ^0.8.4+5
  firebase_core: ^0.3.4
  #firebase_core: any
  firebase_database: ^2.0.3

任何建议请解决非常感谢!

标签: android-studiogradleflutter

解决方案


我认为您的问题与androidX[正如我在错误中看到的那样] 以及您使用firebase_auth: ^0.8.4+5.

1.使用最新版本的android studio

  1. 在android studio中打开你的flutter项目,去Refactor,选择Migrate to androidX。
  2. 当提示使用窗口在新选项卡中打开窗口[在新的 android studio 窗口中打开] 时,这将在此窗口中打开您的 android 应用程序文件夹,再次选择迁移到 android X。完成该过程后,导航到底部并选择重构。再次午餐你的应用程序

希望这有助于检查这一点:https ://medium.com/@swhussain110/how-to-migrate-your-flutter-app-to-androidx-9a78eaaa924b


推荐阅读