软件编程
位置:首页>> 软件编程>> Android编程>> 解决VSCode调试react-native android项目错误问题

解决VSCode调试react-native android项目错误问题

作者:晒干的老咸鱼  发布时间:2023-10-14 02:02:11 

标签:VSCode,调试,react-native,android

如果运行react-native android项目出现如下错误:

解决VSCode调试react-native android项目错误问题

解决办法如下:

一、执行adb devices,判断adb有没有断,

二、如果是adb断了就使用一下步骤 


adb reverse tcp:8081 tcp:8081
npm start

如果adb没断,直接 


npm start

如果执行gradle ass打包命令进行打包之后,出现如下错误:

解决VSCode调试react-native android项目错误问题

1、检查react-native项目工程目录下的index.js里面的AppRegistry.registerComponent(appName, () => App);看注册的项目名是什么,这个注册的项目名很重要;

2、检查android工程下的MainActivity的以下方法返回的是什么:


@Override
protected String getMainComponentName() {
 return "whzsagent";
}

3、检查android工程app/src/main/assets/index.android.bundle文件当中r.exports={name:"whzsagent",displayName:"whzsagent"}},APP_ANDROID_UPDATE_TYPE:'whzsagent-android',APP_IOS_UPDATE_TYPE:'whzsagent-ios'这4个地方

4、检查ios目录下的AppDelegate.m文件的如下方法:


RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
             moduleName:@"whzsagent"
           initialProperties:nil
            launchOptions:launchOptions];

以上4个地方返回的值要是统一的,否则打包之后启动app运行就会报以上错误。

有时候修改了ip地址,修改了app的包名,app注册模块名等之后,打包apk再运行时会发现要么地址总是指向不对,要么就是启动异常,这个时候可能就是app/src/main/assets/index.android.bundle文件导致的,必要时需要重新编译该文件

app/src/main/assets/index.android.bundle文件的编译方法为:

第一步:在Android/app/src/main目录下创建一个空的assets文件夹
第二步: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/

来源:https://blog.csdn.net/chali1314/article/details/111170001

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com