Flutter:如果Cloud_firestore或其依赖项与AndroidX不兼容,Cloud_firestore将破坏您的Android构建

时间:2019-02-21 07:52:07

标签: flutter google-cloud-firestore barcode-scanner

我不能同时使用这两个flutter插件:

  cloud_firestore: ^0.9.0+2
  barcode_scan: ^0.0.8

运行时发生错误:

D8: Program type already present: android.arch.core.util.Function
     *********************************************************
WARNING: This version of cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX.
         See https: //goo.gl /CP92wY 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.
         *********************************************************

FAILURE: Build failed with an exception.

当我删除其中之一时,它已在Android手机上编译并运行。但是两者不能在一起。如何解决?

3 个答案:

答案 0 :(得分:1)

报告barcode_scan的问题,以使其针对AndroidX更新。

在新的barcode_scan版本可用之前,将插件限制为不依赖AndroidX的版本:

cloud_firestore: ^0.8.2

或手动更新barcode_scan,如 https://github.com/flutter/flutter/issues/28207#issuecomment-465600796

答案 1 :(得分:1)

简而言之

将multidex库添加到android应用依赖项(/android/app/build.gradle)

...
android {
  ...
  defaultConfig {
    ...
    multiDexEnabled true
  }
  ...
}
...
dependencies {
  implementation 'com.android.support:multidex:1.0.3' // use latest version
  ...
}
...

在android目录下 gradel.properties文件

添加

android.useAndroidX=true
android.enableJetifier=true

答案 2 :(得分:0)

找到了解决方案(至少对我而言)!

我遇到了以下问题:

[+1498 ms] > Task :app:crashlyticsUploadDeobsRelease
[        ] > Task :cloud_firestore:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_analytics:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_auth:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_core:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_crashlytics:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_dynamic_links:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_messaging:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_ml_vision:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :firebase_remote_config:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :flutter_local_notifications:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :google_sign_in:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :image_picker:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :share:prepareLintJarForPublish UP-TO-DATE
[        ] > Task :shared_preferences:prepareLintJarForPublish UP-TO-DATE
[+15399 ms] > Task :app:lintVitalRelease FAILED
[        ]          *********************************************************
[        ] WARNING: This version of cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX.
[        ]          
[        ]          This warning prints for all Android build failures. The real root cause of the error may be unrelated.
[        ]          *********************************************************
[        ] 317 actionable tasks: 273 executed, 44 up-to-date
[ +372 ms] Running Gradle task 'assembleRelease'... (completed in 75.7s)
[        ] *******************************************************************************************
[        ] The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
[        ] 

似乎是运行器版本 1.2.1 引起的!

在我更改为版本 1.2.0 后,它开始工作了。

因此,我从android/app/build.gradle更改了以下行

androidTestImplementation 'androidx.test:runner:1.2.1'

androidTestImplementation 'androidx.test:runner: 1.2.0'

(注意:此外,不要忘记在Firebase控制台中添加要在应用程序中使用的所有 SHA证书指纹。)