Android打包assembleRelease时verifyReleaseResources失败问题求助
React Native Android assembleRelease构建中verifyReleaseResources持续失败
构建环境信息
System: OS: macOS 12.6 CPU: (10) x64 Apple M1 Max Memory: 22.59 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node Yarn: 1.22.18 - ~/github/snackpass/snackpass-client/node_modules/.bin/yarn npm: 8.19.2 - /opt/homebrew/bin/npm Watchman: 2022.10.31.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: Dolphin 2021.3.1 Patch 1 Dolphin 2021.3.1 Patch 1 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild Languages: Java: 11.0.11 - /Users/alitamoore/.jenv/shims/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.1 => 17.0.1 react-native: ^0.64.4 => 0.64.4 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found
遇到的错误
1. Argfile未找到
Argfile not found: /Users/alitamoore/Library/Application Support/kotlin/daemon/promotedai_react-native-metrics_release
2. Kotlin版本不兼容
/Users/alitamoore/.gradle/caches/transforms-3/39d9fb5957939f0b72af860a8de1b4e0/transformed/jetified-kotlin-stdlib-jdk7-1.6.10.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15. /Users/alitamoore/.gradle/caches/transforms-3/556bb75edc66f947ffbea3dd348ad797/transformed/jetified-kotlin-stdlib-common-1.6.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15. /Users/alitamoore/.gradle/caches/transforms-3/572b2229271f904a5c21007cf91f4994/transformed/jetified-react-native-0.71.0-rc.0-release-api.jar!/META-INF/ReactAndroid_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15. /Users/alitamoore/.gradle/caches/transforms-3/687b7f7119d3db63f03c30ceb978b8e7/transformed/jetified-kotlin-stdlib-1.6.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15. /Users/alitamoore/.gradle/caches/transforms-3/b89184fd2243c0ba9c21f04aac02ee1a/transformed/jetified-kotlin-stdlib-jdk8-1.6.10.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
3. 强制指定Kotlin版本为1.6.0后出现资源链接失败
Execution failed for task ':promotedai_react-native-metrics:verifyReleaseResources'. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > 1 exception was raised by workers: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed AAPT: /Users/alitamoore/github/snackpass/snackpass-client/node_modules/@promotedai/react-native-metrics/android/build/intermediates/res/merged/release/layout/autofill_inline_suggestion.xml:18: error: resource attr/autofillInlineSuggestionChip (aka ai.promoted:attr/autofillInlineSuggestionChip) not found. /Users/alitamoore/github/snackpass/snackpass-client/node_modules/@promotedai/react-native-metrics/android/build/intermediates/res/merged/release/layout/autofill_inline_suggestion.xml:25: error: resource attr/autofillInlineSuggestionStartIconStyle (aka ai.promoted:attr/autofillInlineSuggestionStartIconStyle) not found. /Users/alitamoore/github/snackpass/snackpass-client/node_modules/@promotedai/react-native-metrics/android/build/intermediates/res/merged/release/layout/autofill_inline_suggestion.xml:32: error: resource attr/autofillInlineSuggestionTitle (aka ai.promoted:attr/autofillInlineSuggestionTitle) not found. /Users/alitamoore/github/snackpass/snackpass-client/node_modules/@promotedai/react-native-metrics/android/build/intermediates/res/merged/release/layout/autofill_inline_suggestion.xml:41: error: resource attr/autofillInlineSuggestionSubtitle (aka ai.promoted:attr/autofillInlineSuggestionSubtitle) not found. /Users/alitamoore/github/snackpass/snackpass-client/node_modules/@promotedai/react-native-metrics/android/build/intermediates/res/merged/release/layout/autofill_inline_suggestion.xml:50: error: resource attr/autofillInlineSuggestionEndIconStyle (aka ai.promoted:attr/autofillInlineSuggestionEndIconStyle) not found. error: failed linking file resources.
注:该错误具有不确定性,清理缓存后偶尔能构建成功
解决步骤
处理Argfile未找到问题
- 终止所有Kotlin守护进程:
pkill -f kotlin-daemon - 删除Kotlin守护进程缓存目录:
rm -rf ~/Library/Application\ Support/kotlin/daemon/
处理Kotlin版本不兼容问题
React Native 0.64.x默认适配Kotlin 1.5.31,需统一项目所有模块的Kotlin版本:
- 在项目根目录
android/build.gradle中添加全局版本配置:buildscript { ext { kotlinVersion = "1.5.31" } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" // 保留其他原有依赖 } } - 强制所有子模块使用统一版本,在
android/build.gradle中添加:subprojects { afterEvaluate { project -> if (project.hasProperty("android")) { project.dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion") { force = true } implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") { force = true } } } } }
处理资源链接失败问题
该问题源于第三方模块引用了高版本Android SDK资源,需同步项目SDK版本:
- 在
android/build.gradle中升级compileSdkVersion到31(React Native 0.64.x支持的最高稳定版本):ext { compileSdkVersion = 31 // 保留其他原有配置 } - 清理缓存并重新构建:
cd android && ./gradlew clean assembleRelease - 若问题仍存在,修改第三方模块配置:
- 打开
node_modules/@promotedai/react-native-metrics/android/build.gradle,将compileSdkVersion和targetSdkVersion改为与项目一致的版本 - 使用
patch-package工具保存修改,避免依赖重装后配置丢失
- 打开
内容的提问来源于stack exchange,提问作者Alita
相关产品推荐
相关产品推荐

