使用 react-native-razorpay 时反应本机 apk 构建失败

react native apk build fail when using react-native-razorpay

我正在尝试为我的 react-native 代码构建一个签名的 apk。我已经将 react-native-razorpay 库用于支付集成目的。 在我的项目根目录 运行 cd android && ./gradlew assembleRelease 上,我遇到了以下错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-razorpay:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* 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 22s
102 actionable tasks: 2 executed, 100 up-to-date

虽然 运行 ./gradlew assembleRelease --info 我在最后几行得到关注-

....
....

Successfully started process 'command '/Users/clove/Library/Android/sdk/build-tools/27.0.3/aapt''
/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v24/values-v24.xml:3:5-157: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.

/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v24/values-v24.xml:4:5-135: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.

/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v26/values-v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.


> Task :react-native-razorpay:verifyReleaseResources FAILED
Putting task artifact state for task ':react-native-razorpay:verifyReleaseResources' into context took 0.0 secs.
Up-to-date check for task ':react-native-razorpay:verifyReleaseResources' took 0.0 secs. It is not up-to-date because:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':react-native-razorpay:verifyReleaseResources'.
Unable do incremental execution: full task run
QueuedCruncher is using /Users/clove/Library/Android/sdk/build-tools/27.0.3/aapt

Shutdown finished in 0ms

:react-native-razorpay:verifyReleaseResources (Thread[Daemon worker Thread 18,5,main]) completed. Took 0.402 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-razorpay:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* Try:
Run with --stacktrace option to get the stack trace. Run with --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 1m 16s
102 actionable tasks: 9 executed, 93 up-to-date

找到解决办法。原来问题是由于配置不匹配造成的。我使用的 gradle 版本高于 3,这需要 android sdk 版本 25 或更高版本。而 react-native-razorpay 随 sdk 版本 23 一起提供。所以我在 node_modules 中更改了这些设置并且构建成功完成。