React-native

打包APK

运行./gradlew assembleRelease   报以下错误

> Task :@react-native-community_cameraroll:verifyReleaseResources FAILED

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
                 Welcome to React Native!
                Learn once, write anywhere


info Writing bundle output to:, /Users/pxc-04/newnssapp/android/app/build/generated/assets/react/release/index.android.bundle
info Writing sourcemap output to:, /Users/pxc-04/newnssapp/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 112 asset files
info Done copying assets

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':@react-native-community_cameraroll:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource compilation failed
     AAPT: /Users/pxc-04/newnssapp/node_modules/@react-native-community/cameraroll/android/build/intermediates/res/merged/release/layout-v26/abc_screen_toolbar.xml: error: file not found.
     
         

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 57s
515 actionable tasks: 15 executed, 500 up-to-date

参考GPT和自己的思路:

这个错误是因为编译过程中发现找不到文件 /Users/pxc-04/newnssapp/node_modules/@react-native-community/cameraroll/android/build/intermediates/res/merged/release/layout-v26/abc_screen_toolbar.xml。可以尝试以下几种方法:

  1. 清除缓存并重新编译。操作方式为:在项目根目录下运行 rm -rf android/.gradle,然后重新执行 ./gradlew assembleRelease。

  2. 更新依赖项。可能是因为依赖项版本太低,导致编译错误。可以尝试更新 @react-native-community/cameraroll 的版本,然后重新编译。

  3. 检查文件目录。检查一下项目的结构,看看 abc_screen_toolbar.xml 是否存在于相应的文件夹中。

希望这些方法能够帮助你解决问题。