英文:
Flutter: Firebase - The plugin cloud_firestore requires a higher Android SDK version
问题
Flutter 要求我在 /android/app/build.gradle 文件中使用以下代码:
android {
defaultConfig {
minSdkVersion 19
}
}
但这段代码已经包含在文件中:
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 19
targetSdkVersion 31
}
}
我该如何解决这个问题?
英文:
Flutter wants me to use the following code in my /android/app/build.gradle file:
android {
defaultConfig {
minSdkVersion 19
}
}
But this code is already contained in the file:
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 19
targetSdkVersion 31
}
}
How can I solve this issue?
Error log
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
答案1
得分: 1
更新compileSdkVersion
和targetSdkVersion
到33,然后尝试:
android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 19
targetSdkVersion 33
}
}
确保你已经更新了defaultConfig
,如果它已经存在,否则你可以创建一个新的defaultConfig
块。
已编辑
如果你有两个defaultConfig
块,确保你将它们合并在一起,不要遗漏versionCode
和versionName
。
根据讨论的建议:如果你已经创建了一个APK文件,然后删除\build\app\outputs\flutter-apk\app.apk
,并运行flutter create
以避免在构建时出现版本不兼容的问题。
英文:
Update compileSdkVersion
and targetSdkVersion
to 33, then try
android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 19
targetSdkVersion 33
}
}
Make sure you are updating the defaultConfig
if already exist, otherwise you can create block defaultConfig
.
Edited
If you have two defaultConfig
block, then make sure you merge both without missing versionCode
and versionName
.
As per the discussion made: If you already created an apk, then delete \build\app\outputs\flutter-apk\app.apk
and flutter create
to avoid vision incompatibility on build.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论