解决VSCode调试react-native android项目错误问题
作者:晒干的老咸鱼 时间:2023-10-14 02:02:11
如果运行react-native android项目出现如下错误:
解决办法如下:
一、执行adb devices,判断adb有没有断,
二、如果是adb断了就使用一下步骤
adb reverse tcp:8081 tcp:8081
npm start
如果adb没断,直接
npm start
如果执行gradle ass打包命令进行打包之后,出现如下错误:
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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mybatis group by substr函数传参报错的解决
Java注解(annotation)简述
![](https://img.aspxhome.com/file/2023/4/62824_0s.png)
详解Java分布式事务的 6 种解决方案
Android XML設置屏幕方向(android:screenOrientation)详解
Java 重命名 Excel 工作表并设置工作表标签颜色的示例代码
![](https://img.aspxhome.com/file/2023/1/65211_0s.png)
java中超过long范围的超大整数相加算法详解(面试高频)
![](https://img.aspxhome.com/file/2023/0/61850_0s.png)
使用Java Minio搭建自己的文件系统详解
![](https://img.aspxhome.com/file/2023/7/130907_0s.jpg)
springboot前端传参date类型后台处理的方式
![](https://img.aspxhome.com/file/2023/1/85941_0s.png)
MyBatis字段名和属性名不一致的解决方法
Kotlin Lambda表达式实践使用介绍
Android Dispatchers.IO线程池深入刨析
![](https://img.aspxhome.com/file/2023/8/138198_0s.png)
Android使用Room操作数据库流程详解
SpringBoot与Angular2的集成示例
在Eclipse中运行Solr 基础知识
Gradle的使用教程详解
![](https://img.aspxhome.com/file/2023/0/84220_0s.png)
MyBatis注解实现动态SQL问题
java实现三角形分形山脉
![](https://img.aspxhome.com/file/2023/6/113386_0s.jpg)
在Visual Studio上构建C++的GUI框架wxWidgets的开发环境
![](https://img.aspxhome.com/file/2023/2/139452_0s.png)