RN(React Native)的应用程序在雷电模拟器可以运行,安卓真机运行失败问题解决记录

 yarn react-native build-android打包的apk在真机安卓运行提示:

Unable to load script . Make sure you ' re either running Metro ( run ' npx react - native start ') or that your bundle 
' index . android . bundle ' is packaged correctly for release .
 jniLoadScriptFromAssets CatalystInstanceImpl . java 
 loadScriptFromAssets 
 CatalystInstanceImpl . java :239
 loadScript 
 JSBundleLoader . java :29
 runJSBundle 
 CatalystInstanceImpl . java :268
 createReactContext 
 ReactInstanceManager . java :1413
-$$ Nest $ mcreateReactContext null 
 run 
 ReactInstanceManager . java :1111
 run 
 Thread . java :929
 DISMISS 
( ESC )
 RELOAD 
( R , R )

主要原因是打包bundle 中出问题,

解决方法:

第一步、在项目目录执行生成bundle

PS E:\ProjectCode\react\Health-Monitoring-System\android> npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output app/src/main/assets/index.android.bundle --assets-dest app/src/main/res
                Welcome to Metro v0.73.10
              Fast - Scalable - Integrated


info Writing bundle output to:, app/src/main/assets/index.android.bundle
info Done writing bundle output
info Copying 10 asset files
info Done copying assets

第二步、重新打包apk

PS E:\ProjectCode\react\Health-Monitoring-System\android> yarn react-native build-android
yarn run v1.22.19
$ E:\ProjectCode\react\Health-Monitoring-System\node_modules\.bin\react-native build-android
info Starting JS server...
info Building the app...

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libcxxcomponents.so, libevent-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libfabricjni.so, libfb.so, libfbjni.so, libflipper.so, libfolly_runtime.so, libglog.so, libglog_init.so, libhermes.so, libhermes_executor.so, libimagepipeline.so, libjsi.so, libjsijniprofiler.so, libjsinspector.so, liblogger.so, libmapbufferjni.so, libnative-filters.so, libnative-imagetranscoder.so, libreact_codegen_rncore.so, libreact_config.so, libreact_debug.so, libreact_nativemodule_core.so, libreact_newarchdefaults.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, libreactnativeblob.so, libreactnativejni.so, libreactperfloggerjni.so, librrc_image.so, librrc_root.so, librrc_scrollview.so, librrc_text.so, librrc_textinput.so, librrc_unimplementedview.so, librrc_view.so, libruntimeexecutor.so, libturbomodulejsijni.so, libyoga.so.

BUILD SUCCESSFUL in 27s
127 actionable tasks: 33 executed, 94 up-to-date

RN(React Native)的应用程序在雷电模拟器可以运行,安卓真机运行失败问题解决记录_第1张图片

模拟器使用记录:

adb devices可能看不到雷电模拟器,但可直接connect去使用

PS E:\ProjectCode\react\Health-Monitoring-System\android> yarn android --deviceId=127.0.0.1:5555
yarn run v1.22.19
$ react-native run-android --deviceId=127.0.0.1:5555
info JS server already running.
info Building the app...

> Task :app:createBundleReleaseJsAndAssets
warning: the transform cache was reset.
                Welcome to Metro v0.73.10
              Fast - Scalable - Integrated

react native安装运行使用中经常出现readtimeout的解决方法:

直接相应链接拷贝到浏览器下载后直接放到对应到目录里再重新运行即可解决

C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.codehaus.groovy

你可能感兴趣的:(react,native,android,react.js)