Flutter运行debug报错:依赖minCompileSdk 31高于compileSdkVersion 30如何解决
Flutter Debug模式Android构建失败解决方案
完整报错日志
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 (31) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-30). Dependency: androidx.work:work-runtime:2.7.0-beta01. AAR metadata file: /home/javeed/.gradle/caches/transforms-2/files-2.1/9d7505e2cdbb28aad564446b7c211aea/work-runtime-2.7.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties. * 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 19s The build failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetifier to solve the incompatibility. Building plugin device_info... Exception: The plugin device_info could not be built due to the issue above. Exited (sigterm)
核心原因
项目当前配置的Android compileSdk版本为30,依赖的androidx.work:work-runtime:2.7.0-beta01要求最低compileSdk版本为31,版本校验不通过,Jetifier无法解决该类版本不兼容问题,最终导致device_info插件构建失败。
解决方案
方案1:升级项目compileSdk版本(推荐)
打开项目android/app/build.gradle文件,修改compileSdk配置:
修改后重新执行构建即可正常编译。android { // 原有值为30,修改为31 compileSdkVersion 31 defaultConfig { // 可选同步升级targetSdkVersion,避免运行时兼容问题 targetSdkVersion 31 } }方案2:强制指定work-runtime兼容版本
若暂时不想升级compileSdk版本,可在项目android/build.gradle中添加强制版本约束,使用符合当前compileSdk要求的work-runtime版本:
2.6.0版本的work-runtime最低要求compileSdk为30,可匹配当前项目配置。allprojects { configurations.all { resolutionStrategy { force 'androidx.work:work-runtime:2.6.0' } } }方案3:替换旧版device_info插件
旧版device_info已停止维护,建议替换为官方维护的新版device_info_plus插件,修改pubspec.yaml中的依赖即可,新版插件已适配多版本compileSdk兼容问题。
内容的提问来源于stack exchange,提问作者Javeed Ishaq
相关产品推荐
相关产品推荐

