修复 React-Native run-android 上的构建失败
Posted
技术标签:
【中文标题】修复 React-Native run-android 上的构建失败【英文标题】:Fix Build Failed on React-Native run-android 【发布时间】:2022-01-19 10:47:45 【问题描述】:我是反应原生的新手。我开始了一个新项目并遵循了所有步骤。我之前有 android Studio,我用它启动了模拟器。运行 npx react-native run-android 命令后,我收到此错误。这是
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 870 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
> Task :app:compileDebugJavaWithJavac
> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libbetter.so, libc++_shared.so, libevent-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libfabricjni.so, libfb.so, libfbjni.so, libflipper.so, libfolly_futures.so, libfolly_json.so, libglog.so, libglog_init.so, libhermes-executor-common-debug.so, libhermes-executor-common-release.so, libhermes-executor-debug.so, libhermes-executor-release.so, libhermes-inspector.so, libimagepipeline.so, libjsc.so, libjscexecutor.so, libjsi.so, libjsijniprofiler.so, libjsinspector.so, liblogger.so, libmapbufferjni.so, libnative-filters.so, libnative-imagetranscoder.so, libreact_codegen_rncore.so, libreact_debug.so, libreact_nativemodule_core.so, libreact_render_animations.so, libreact_render_attributedstring.so, libreact_render_componentregistry.so, libreact_render_core.so, libreact_render_debug.so, libreact_render_graphics.so, libreact_render_imagemanager.so, libreact_render_leakchecker.so, libreact_render_mapbuffer.so, libreact_render_mounting.so, libreact_render_runtimescheduler.so, libreact_render_scheduler.so, libreact_render_telemetry.so, libreact_render_templateprocessor.so, libreact_render_textlayoutmanager.so, libreact_render_uimanager.so, libreact_utils.so, libreactconfig.so, libreactnativeblob.so, libreactnativejni.so, libreactnativeutilsjni.so, libreactperfloggerjni.so, librrc_image.so, librrc_modal.so, librrc_progressbar.so, librrc_root.so, librrc_scrollview.so, librrc_slider.so, librrc_switch.so, librrc_text.so, librrc_textin
> Task :app:installDebug FAILED
31 actionable tasks: 31 executed
Note: E:\Coding\React Native\RNdasar\android\app\src\debug\java\com\rndasar\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* 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 1m 47s
error Failed to install the app. Make sure you have an Android emulator running or a device connected.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Note: E:\Coding\React Native\RNdasar\android\app\src\debug\java\com\rndasar\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* 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 1m 47s
at makeError (E:\Coding\React Native\RNdasar\node_modules\execa\index.js:174:9)
at E:\Coding\React Native\RNdasar\node_modules\execa\index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (E:\Coding\React Native\RNdasar\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (E:\Coding\React Native\RNdasar\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
如何解决?
【问题讨论】:
【参考方案1】:错误提示没有连接设备。
表示没有模拟器或设备连接到您的系统。
-
如果您有模拟器,请在运行 react native 应用程序之前运行它。如果没有,请先创建一个模拟器。
点击此链接创建一个:create emulator
-
如果您想在手机上运行它。用数据线连接它,然后在手机上打开 USB 调试。
希望这能解决你的问题
【讨论】:
以上是关于修复 React-Native run-android 上的构建失败的主要内容,如果未能解决你的问题,请参考以下文章
修复 React-Native run-android 上的构建失败
如何修复错误读取“node_modules/react-native/ReactCommon/yoga/yoga/log.cpp”React Native
如何修复React-Native中的“路由组件'Principal'必须是React组件”错误