如何解决Flutter运行时gradle执行报错与Android资源链接失败问题
Flutter 运行Android端资源链接失败报错解决
错误信息
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
关联配置
AndroidManifest.xml 配置
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.my_app"> <!-- io.flutter.app.FlutterApplication是android.app.Application的子类,会在onCreate方法中调用FlutterMain.startInitialization(this); 大多数情况可直接保留原配置,若需添加额外功能,可继承或重写FlutterApplication后在此处填写自定义类 --> <uses-permission android:name="android.permission.INTERNET"/> <application android:name="io.flutter.app.FlutterApplication" android:label="my_app" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <!-- 请勿删除下方meta-data配置,Flutter工具会通过该配置生成GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="2" /> </application> </manifest>
已尝试的操作
已在gradle.properties中添加org.gradle.jvmargs=-Xmx1536M配置,无效。
解决方案
- 校验LaunchTheme主题配置
检查android/app/src/main/res/values/styles.xml文件是否存在声明的LaunchTheme主题,该配置缺失是触发此报错的高频原因。标准配置参考:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowBackground">@drawable/launch_background</item> </style> <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowBackground">?android:colorBackground</item> </style> </resources>
- 调整SDK版本配置
打开android/app/build.gradle,将compileSdkVersion调整为33及以上,minSdkVersion调整为21及以上,避免与第三方依赖的SDK要求不匹配。 - 清理缓存重建
依次执行以下命令重置构建缓存:
- 项目根目录执行
flutter clean - 删除
android目录下的.gradle文件夹 - 执行
flutter pub get重新拉取依赖 - 重新运行应用
- 排查插件冲突
若报错出现在新增Flutter插件之后,回退插件版本至稳定版,或核对插件文档要求的Android配置是否完整,比如是否需要开启Jetifier、是否需要额外的权限声明。
内容的提问来源于stack exchange,提问作者Mike Osborn
相关产品推荐
相关产品推荐

