【发布时间】:2019-03-31 19:51:45
【问题描述】:
我在尝试构建 react native android release build 时遇到以下错误。我所有的图片都是 svg 格式。
:app:generateReleaseResources UP-TO-DATE
:app:mergeReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> /Users/shamnad.shaji/Workspace/React-Native/project/android/app/src/main/res/drawable-mdpi/images_defaultprofile.svg: Error: The file name must end with .xml or .png
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.514 secs
我用谷歌搜索了这个错误,人们建议在我的 gradle.properties 文件中包含 android.disableResourceValidation=true 选项。
我的gradle.properties 看起来像这样。
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=password
MYAPP_RELEASE_KEY_PASSWORD=password
android.disableResourceValidation=true
我运行发布版本的步骤是。
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
cd android/
./gradlew assembleRelease
有人可以建议我怎么做吗?
【问题讨论】:
-
当我们在 android studio 中包含一个 svg 时,它会自动变成 .xml 你可能想要重命名它
-
那么我必须重命名每个文件,对吗? .
<Image source={require('../../images/default-profile.svg')} />。这就是我如何使用它们对 android 和 ios 通用的。 -
将这些转换为 .png 它将删除这些错误github.com/react-native-community/react-native-svg/issues/109
-
是的,这是唯一的方法。我做到了,现在效果很好。
-
@ShamnadPS,我只在发布时遇到同样的问题,你设法解决了吗?
标签: android react-native svg