Flutter: Cloud_firestore will break your Android build if it or its dependencies aren't compatible with AndroidX

扶醉桌前 提交于 2021-02-10 07:04:46

问题


I can not use these both flutter plugins together:

  cloud_firestore: ^0.9.0+2
  barcode_scan: ^0.0.8

When run, error occured:

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.

it compiled and runned on Android phone when I remove one of them. But both can not go together. How to fix?


回答1:


In short

Add multidex library to android app dependency (/android/app/build.gradle)

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

under android directory gradel.properties file

Add

android.useAndroidX=true
android.enableJetifier=true



回答2:


Found the solution (for me, at least) !

I had the following issue:

[+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.
[        ] 

It seems that runner version 1.2.1 was the responsible for this !

After I changed to version 1.2.0 it worked.

So, I changed the following line from android/app/build.gradle

androidTestImplementation 'androidx.test:runner:1.2.1'

to

androidTestImplementation 'androidx.test:runner: 1.2.0'

(Note: Also, don't forget to add in Firebase Console all SHA certificate fingerprints you are going to use in your apps.)




回答3:


Report an issue with barcode_scan to have it updated for AndroidX.

Limit the plugin to a version that does not depend on AndroidX until a new barcode_scan version becomes available:

cloud_firestore: ^0.8.2

Or update barcode_scan manually like mentioned in https://github.com/flutter/flutter/issues/28207#issuecomment-465600796



来源:https://stackoverflow.com/questions/54801856/flutter-cloud-firestore-will-break-your-android-build-if-it-or-its-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!