我曾try 按照教程为我的Ffltter项目设置Firebase,但在设置好一切后,当我从pub.dev导入Firebase包时,当我试图在模拟器上运行我的代码时,开始出现错误.我导入的包是:

firebase_core: ^2.14.0
firebase_auth: ^4.6.3
cloud_firestore: ^4.8.1

此外,我面临的错误是:

C:\Users\ahmad\Desktop\flutter projects\chat_app\android\app\src\debug\AndroidManifest.xml Error:
    uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore] C:\Users\ahmad\Desktop\flutter projects\chat_app\build\cloud_firestore\intermediates\merged_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 19,
        or use tools:overrideLibrary="io.flutter.plugins.firebase.firestore" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore] C:\Users\ahmad\Desktop\flutter projects\chat_app\build\cloud_firestore\intermediates\merged_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 19,
        or use tools:overrideLibrary="io.flutter.plugins.firebase.firestore" to force usage (may lead to runtime failures)

* 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 26s
 Flutter Fix
 The plugin cloud_firestore requires a higher Android SDK version.                             
 Fix this issue by adding the following to the file C:\Users\ahmad\Desktop\flutter             
 projects\chat_app\android\app\build.gradle:                                                   
 android {                                                                                     
   defaultConfig {                                                                             
     minSdkVersion 19                                                                          
   }                                                                                           
 }                                                                                             
                                                                                               
 Note that your app won't be available to users running Android SDKs below 19.                
 Alternatively, try to find a version of this plugin that supports these lower versions of the 
 Android SDK.                                                                                  
 For more information, see:                                                                    
 https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration                
Exception: Gradle task assembleDebug failed with exit code 1

根据上面的错误,我转到相应的build.gradle并将代码更改为:

    minSdkVersion flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName

至此:minSdkVersion 19

我得到以下错误:

ERROR:D8: Cannot fit requested classes in a single dex file (# methods: 102117 > 65536)
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

* what went wrong
Execution failed for task ':app:mergeExtDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
   > There was a failure while executing work items
      > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
         > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
           The number of method references in a .dex file cannot exceed 64K.
           Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

* 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 9s
[!] App requires Multidex support
    Multidex support is required for your android app to build since the number of methods has exceeded 64k. See https://docs.flutter.dev/deployment/android#enabling-multidex-support for more information. You may pass the --no-multidex flag to skip Flutter's multidex support to use a manual solution.
    Flutter tool can add multidex support. The following file will be added by flutter:
        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java
cannot prompt without a terminal ui
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

推荐答案

您的设置对minsdk版本19有要求,而您当前的minsdk版本是16.

如果您使用的是低于2.8的Ffltter版本,则在您的android/app/build.gradle文件中将minSdkVersion更改为19,如下所示

defaultConfig {
        ...
        minSdkVersion 19 // 
        ...
    }

如果您使用的是高于2.8的版本,请在您的android/local.properties文件中添加

flutter.minSdkVersion=19

完成上述更改后,执行flutter clean以清除以前的缓存.
另外,这change-android-minsdkversion-in-flutter篇博客可能会有所帮助.

Flutter相关问答推荐

关闭视频通话,相机仍在运行!(Flutter WebRTC)

如何更新文本字段的基础上的选定下拉菜单?

使用自定义控制器将项插入到ListView中时行为不正确

如何在Firebase项目中更改包名称和包ID

来自FirebaseAuth的错误DisplayName和邮箱在Flutter应用程序中给出错误

使用ImageFilter模糊并剪裁同一renderObject中的元素

如何在Flutter 安全存储器中存储对象值?

集装箱堆放和定位时的高度问题

使用 Firebase Realtime 实现高效流式传输

2023 年如何使用 youtube_explode_dart 包下载 URL?

围绕父组件旋转位置组件

什么最接近 Dart 的 List.asMap().forEach() 返回列表?

忽略异步函数上的 context.mounted 访问 linting 错误是否安全?

Flutter - 展开图标无法正常工作

如何从另一个页面访问 Firebase 值?

Flutter sliver 持久化

Flutter snapShot.hasData 为假但响应有数据

如何防止卡子在底部溢出?

Flutter 活跃的互联网连接

如何从用户 Flutter 导航抽屉中隐藏管理菜单