首页 > 解决方案 > 无法构建flutter插件cloud_firestore,因为CloudFirestorePlugin.java使用未经检查或不安全的操作[flutter build apk]

问题描述

我正在构建一个使用多个 firebase 依赖项的颤振应用程序,但 cloud_firestore 依赖项在调试和构建应用程序时总是返回错误。

这是构建日志

You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
    To generate an app bundle, run:
        flutter build appbundle --target-platform android-arm,android-arm64,android-x64
        Learn more on: https://developer.android.com/guide/app-bundle
    To split the APKs per ABI, run:
        flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
        Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...                                
Note: /flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.4+2/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.                                                                 
Note: Some input files use unchecked or unsafe operations.                                                         
Note: Recompile with -Xlint:unchecked for details.                                                                 
Calling mockable JAR artifact transform to create file: /Users/user/.gradle/caches/transforms-2/files-2.1/323813f5a095cba9aa563dadb749a1cb/android.jar with input /Users/user/Library/Android/sdk/platforms/android-28/android.jar
Calling mockable JAR artifact transform to create file: /Users/user/.gradle/caches/transforms-2/files-2.1/ff23381473fa92d0c047c8663bfbe6a6/android.jar with input /Users/user/Library/Android/sdk/platforms/android-27/android.jar
Calling mockable JAR artifact transform to create file: /Users/user/.gradle/caches/transforms-2/files-2.1/43c9f60e6803ddaaef16828845e40f49/android.jar with input /Users/user/Library/Android/sdk/platforms/android-29/android.jar
Removed unused resources: Binary resource data reduced from 329KB to 261KB: Removed 20%                            

FAILURE: Build failed with an exception.                                                                           

* What went wrong:                                                                                                 
Execution failed for task ':google_sign_in:verifyReleaseResources'.                                                
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade                  
   > Android resource linking failed                                                                               
     /Users/user/.gradle/caches/transforms-2/files-2.1/9dacf9516413cf5e5b34c6b4508340e4/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.

     /Users/user/.gradle/caches/transforms-2/files-2.1/9dacf9516413cf5e5b34c6b4508340e4/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.


* Try:                                                                                                             
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org                                                                         

BUILD FAILED in 7m 10s                                                                                             
Running Gradle task 'assembleRelease'...                                                                           
Running Gradle task 'assembleRelease'... Done                     441.0s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
✏️  Creating 'android/settings_aar.gradle'...                       35ms
✓ 'android/settings_aar.gradle' created successfully.
Building plugin cloud_firestore...
The plugin cloud_firestore could not be built due to the issue above.

使用的 pubspec.yaml firebase 依赖项:

firebase_core: ^0.4.4+3
cloud_firestore: ^0.13.4+2
firebase_auth: ^0.15.5+2 

任何有工作的 firebase 依赖项的人请在下面分享它们。

标签: androidfirebaseflutterfirebase-realtime-databasegoogle-cloud-firestore

解决方案


要解决此问题,请尝试两件事:

  1. 在项目/android/app/build.gradle

    defaultConfig {
      ...
       multiDexEnabled true
    }
    
  2. 在终端运行flutter pub upgrade


推荐阅读