Flutter:Firebase -插件cloud_firestore需要更高的Android SDK版本

lsmepo6l  于 2023-02-25  发布在  Flutter
关注(0)|答案(1)|浏览(204)

Flutter希望我在/android/app/build.gradle文件中使用以下代码:

android {                                                                                                  
    defaultConfig {                                                                                         
      minSdkVersion 19                                                                                       
    }                                                                                                        
}

但此代码已包含在文件中:

android {
    compileSdkVersion 31

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 31
    }
}

我该如何解决这个问题?
错误日志

PS C:\Coding\nutritious> flutter run
Using hardware rendering with device sdk gphone64 x86 64. If you notice graphics artifacts, consider enabling software rendering
with "--enable-software-rendering".
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Building with Flutter multidex support enabled.
C:\Coding\nutritious\android\app\src\debug\AndroidManifest.xml Error:
        uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore] C:\Coding\nutritious\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:\Coding\nutritious\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 6s
Running Gradle task 'assembleDebug'...                              8,7s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────────────────┐
│ The plugin cloud_firestore requires a higher Android SDK version.                                          │
│ Fix this issue by adding the following to the file C:\Coding\nutritious\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
mfuanj7w

mfuanj7w1#

compileSdkVersiontargetSdkVersion更新为33,然后尝试

android {
    compileSdkVersion 33

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 33
    }
}

如果defaultConfig已存在,请确保您正在更新它,否则您可以创建块defaultConfig

    • 已编辑**

如果您有两个defaultConfig块,那么请确保合并这两个块时不丢失versionCodeversionName
根据所制造的discussion:如果你已经创建了一个apk,那么删除\build\app\outputs\flutter-apk\app.apkflutter create,以避免构建时的视觉不兼容。

相关问题