我只是从React-Native开始。我将Atom用作Genymotion for Emulator的编辑器。该代码运行良好。但这是关于生成Release APK的问题。
我遵循了https://facebook.github.io/react-native/docs/signed-apk-android中的教程,但出现了一些错误。
经过研究,我运行了这些命令
dev_appserver.py
但是我有很多错误。
- 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
一些研究表明,我必须清空 res 文件夹,但是我执行了Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
> Task :realm:forwardDebugPort
adb: error: no devices/emulators found
===========================================================================
WARNING: Failed to automatically forward port 8083.
In order to use Realm in Chrome debugging mode, port 8083 must be forwarded
from localhost to the device or emulator being used to run the application.
You may need to add the appropriate flags to the command that failed:
adb forward tcp:8083 tcp:8083
===========================================================================
> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/assets/react/release/index.android.bundle
info Done writing bundle output
info Copying 6 asset files
info Done copying assets
> Task :app:mergeReleaseResources FAILED
[drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
* 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 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 7m 0s
67 actionable tasks: 4 executed, 63 up-to-date
后又遇到了另一个错误
./gradlew assembleRelease
从Facebook React-native网站进行配置后,我希望有一个APK。知道出了什么问题。
我不知道如何解决此问题。 有什么建议吗?
答案 0 :(得分:2)
好吧,它重复的资源错误。
请参见,
> Task :app:mergeReleaseResources FAILED
[drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backiconmask.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-mdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-xxxhdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
[drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/src/main/res/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png [drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon] /home/maelfosso/Documents/Projects/Apps/Guitou/Customers/jnadia40/ASQQuestionnaire/android/app/build/generated/res/react/release/drawable-hdpi/node_modules_reactnavigationstack_src_views_assets_backicon.png: Error: Duplicate resources
这些是普通drawable
文件夹中的两个相同资源,而其他build/generated/res/react/release
文件夹中的其他资源。
从drawable
中删除这六个文件,它将正常工作。
答案 1 :(得分:1)
删除
/android/app/src/main/res/drawable-xxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon
/android/app/src/main/res/drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backiconmask
/android/app/src/main/res/drawable-mdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon
/android/app/src/main/res/drawable-xhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon
/android/app/src/main/res/drawable-xxxhdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon
/android/app/src/main/res/drawable-hdpi-v4/node_modules_reactnavigationstack_src_views_assets_backicon
如果删除后仍然出现错误,请删除所有可绘制文件夹
答案 2 :(得分:0)
删除构建文件夹android / app / build和android / build
检查可绘制对象中是否有任何重复,如果有则删除
命令:
1)react-native bundle --platform android --dev false --entry-file index.js --bundle-output android / app / src / main / assets / index.android.bundle
2)./ gradlew清洁
3)./gradlew assembleRelease
通过将移动设备连接到pc(可以是模拟器)来替换2和3命令,然后使用该命令 react-native运行android --variant = release 它将直接在android移动版中运行