添加flutter_paypal SDK后Flutter项目构建失败的问题咨询
Flutter添加flutter_paypal SDK后的编译错误解决
遇到的错误
错误1:compileSdkVersion版本不足
One or more plugins require a higher Android SDK version. Fix this issue by adding the following to D:\MyApplication\Application\application\android\app\build.gradle: android { compileSdkVersion 32 ... } FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:checkDebugAarMetadata'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction > The minCompileSdk (32) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.webkit:webkit:1.5.0. AAR metadata file: C:\Users\MyPc\.gradle\caches\transforms-2\files-2.1\1e17c3cecd51956dd096ba6a3522bf2f\webkit-1.5.0\META-INF\com\android\build\gradle\aar-metadata.properties.
错误2:minSdkVersion版本冲突
D:\MyApplication\Application\application\android\app\src\debug\AndroidManifest.xml Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:webview_flutter_android] D:\MyApplication\Application\application\build\webview_flutter_android\intermediates\library_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.webviewflutter" to force usage (may lead to runtime failures)
为什么Manifest中没有uses-sdk:minSdkVersion却出现该错误?
Flutter项目的Android SDK版本配置默认在android/app/build.gradle中定义,而非直接写入AndroidManifest.xml。Gradle构建时会自动将build.gradle里的minSdkVersion、compileSdkVersion等配置注入到Manifest文件中,所以即使你没手动添加uses-sdk标签,项目实际的minSdk版本仍由build.gradle的配置决定。
解决步骤
- 打开项目中的
android/app/build.gradle文件 - 在
android代码块中修改版本配置,同步依赖要求:
android { compileSdkVersion 32 defaultConfig { // 保留原有applicationId、versionCode等配置 minSdkVersion 19 targetSdkVersion 32 } }
- 点击Android Studio右上角的Sync Now按钮,同步Gradle配置
- 重新运行Flutter应用
说明
compileSdkVersion必须与依赖库要求的最低编译版本一致(此处依赖的androidx.webkit:webkit:1.5.0要求32)minSdkVersion需提升至所有依赖库要求的最低版本以上(此处webview_flutter_android要求至少19),避免API不兼容导致运行时崩溃- 不建议使用
tools:overrideLibrary强制忽略版本冲突,这会带来潜在的运行时风险
内容的提问来源于stack exchange,提问作者Stack Overflow
相关产品推荐
相关产品推荐

