在我的flutter项目中设置firebase时遇到困难

wnavrhmk  于 2023-06-24  发布在  Flutter
关注(0)|答案(2)|浏览(204)

我已经尝试按照教程设置firebase为我的Flutter项目,但设置一切后,现在工作完美,当我从www.example.com导入firebase包pub.dev我开始得到错误,当我试图运行我的代码在模拟器上.我导入的包是:

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)
dba5bblo

dba5bblo1#

您的设置对minsdk版本19的要求很高,而您当前的minsdk版本是16。
如果您使用的flutter版本小于2.8,那么在您的android/app/build.gradle文件中将minSdkVersion更改为19

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

如果您使用的版本大于2.8,请在android/www.example.com文件中添加local.properties file, add

flutter.minSdkVersion=19

完成以上更改后,执行flutter clean来清理以前的缓存。
这个change-android-minsdkversion-in-flutter博客可能会有帮助。

jobtbby3

jobtbby32#

在应用程序级别build.gradle中,添加multiDexEnabled true

android {
    compileSdkVersion 33

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

    defaultConfig {
        applicationId "com.example.text"
        minSdkVersion 20        //change to 20
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true       //added this 
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

相关问题