Flutter - 无法构建插件 firebase_core

Posted

技术标签:

【中文标题】Flutter - 无法构建插件 firebase_core【英文标题】:Flutter - The plugin firebase_core could not be built 【发布时间】:2020-06-06 04:15:41 【问题描述】:

我正在为 android 构建 Flutter 版本,而 firebase_core 插件在构建过程中崩溃。以前一切正常,但我重新安装了 Windows、Android Studio 并下载了最新的 Flutter sdk。现在这个 firebase_core 插件的错误出现了。这是我的日志

D:\AndroidProjets\my_app>flutter build apk --split-per-abi
Running Gradle task 'assembleRelease'...
Note: D:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-6.0.9\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\flutter\.pub-cache\hosted\pub.dartlang.org\shared_preferences-0.5.6+2\android\src\main\java\io\flutter\plugins\sharedpreferences\SharedPreferencesPlugin.java:25: warning: [deprecation] getFlutterEngine() in FlutterPluginBinding h
as been deprecated
    setupChannel(binding.getFlutterEngine().getDartExecutor(), binding.getApplicationContext());
                        ^
1 warning
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Removed unused resources: Binary resource data reduced from 658KB to 635KB: Removed 3%
Removed unused resources: Binary resource data reduced from 658KB to 635KB: Removed 3%
Removed unused resources: Binary resource data reduced from 658KB to 635KB: Removed 3%

FAILURE: Build failed with an exception.

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

     C:\Users\.gradle\caches\transforms-2\files-2.1\c5476b279721c45ae2c1305903c71386\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 4m 3s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                     244.7s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin admob_flutter...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                   22.1s
√ Built build\app\outputs\repo.
Building plugin clipboard_manager...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                   20.3s
√ Built build\app\outputs\repo.
Building plugin firebase_analytics...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done                   22.5s
√ Built build\app\outputs\repo.
Building plugin firebase_core...
The plugin firebase_core could not be built due to the issue above.
Running Gradle task 'assembleAarRelease'... 

对于 build.gradle

android 
    compileSdkVersion 29

    sourceSets 
        main.java.srcDirs += 'src/main/kotlin'
    

    lintOptions 
        disable 'InvalidPackage'
    

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId ""
        minSdkVersion 19
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    signingConfigs 
        release 
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
            v1SigningEnabled true
            v2SigningEnabled true
        
    
    buildTypes 
        release 
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true
            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        
    

    aaptOptions 
        cruncherEnabled = false
    

最后是我的 pubspec.yaml 依赖项

cupertino_icons: ^0.1.3
  shared_preferences: ^0.5.6+2
  get_it: ^3.1.0
  http: ^0.12.0+4
  url_launcher: ^5.4.2
  flutter_staggered_animations: ^0.1.2
  cached_network_image: ^2.0.0
  intl: ^0.16.1
  clipboard_manager: ^0.0.4
  flutter_svg: ^0.17.1
  photo_view: ^0.9.2
  rxdart: ^0.23.1
  firebase_core: ^0.4.4
  firebase_analytics: ^5.0.11
  firebase_crashlytics: ^0.1.3
  firebase_messaging: ^6.0.9
  flutter_local_notifications: ^1.1.6
  admob_flutter: ^0.3.4
  auto_direction: ^0.0.4+1
  rate_my_app: ^0.6.0
  flutter_rating_bar: ^3.0.1+1
  flutter_linkify: ^3.1.0

【问题讨论】:

【参考方案1】:

我通过将 clipboard_manager 的 build.gradle 从 compileSdkVersion 27 更新到 28 解决了这个问题,然后一切正常。以下对我有帮助。

https://github.com/flutter/flutter/issues/44760

【讨论】:

不错!真的很有帮助!【参考方案2】:

我认为更改SharedPreference 版本可以解决此问题,请使用shared_preferences: ^0.5.6+1

【讨论】:

以上是关于Flutter - 无法构建插件 firebase_core的主要内容,如果未能解决你的问题,请参考以下文章

如何解决“由于上述问题,无法构建插件 cloud_firestore。”

使用 Firebase In App Messaging 插件时 Flutter 无法编译项目

Flutter Firebase 插件问题:不兼容问题

Flutter XCode-build 错误无法构建模块'firebase_core'

Flutter:由于集成了 Firebase 和 Admob,因此无法构建 iOS 应用程序

FlutterEnginePluginRegistry - 在 Flutter 应用中注册插件 Firebase 的问题