Flutter Android部署Gradle构建报错:SdkVersion兼容性问题
Flutter Android构建失败:device_info模块compileSdk版本不兼容问题
解决方案
1. 升级/替换插件(推荐)
旧版device_info已被官方弃用,直接替换为官方维护的device_info_plus并升级到最新稳定版,彻底解决兼容性问题:
修改pubspec.yaml中的依赖:
dependencies: device_info_plus: ^9.1.1 # 替换为当前最新版本号
执行flutter pub get后重新运行构建命令。
2. 强制指定device_info模块的compileSdk版本
如果暂时不想换插件,在项目根目录的android/build.gradle中添加以下配置,让device_info模块使用与主App一致的compileSdk:
subprojects { afterEvaluate { project -> if (project.name == "device_info") { android { compileSdkVersion 31 // 填你主App的compileSdk版本,比如31或33 } } } configurations.all { resolutionStrategy.eachDependency { details -> // 强制使用稳定版window依赖,避免beta版本的高SDK要求 if (details.requested.group == 'androidx.window') { details.useVersion '1.0.0' } } } }
3. 移除冲突的强制依赖
你当前app/build.gradle中的强制依赖配置可能加剧版本冲突,建议先删除:
// 删掉这段配置 configurations.all { resolutionStrategy { force 'androidx.window:window-java:1.0.0-beta04' }}
问题说明
错误核心是:device_info模块自身编译用的是android-29,但它依赖的androidx.window beta版本要求compileSdk至少31。你修改主App的compileSdk不会影响第三方插件的编译配置,因此需要针对性调整插件的编译版本或替换为兼容的插件版本。
内容的提问来源于stack exchange,提问作者Syhtam
相关产品推荐
相关产品推荐

