Android Studio调试React Native项目

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hxy19971101/article/details/81415728

今天做项目时,在React Native中调用了原生组件,点击按钮时,程序就闪退,在React Native中却看不到程序的log,原生代码log只有在android studio中查看!最后找到了Android Studio运行React Native项目的方法。

1,在 android/app/src/main 目录下创建一个 assets空文件夹

mkdir android/app/src/main/assets
  •  

2,在项目根目录运行

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/
  •  

注意了,是编译index.js而不是index.android.js,因为react-native新版本已经没有index.android.js和index.ios.js两个文件了,只有一个index.js文件,所以要编译index.js 
会发现 assets文件夹下多出两个文件

index.android.bundle      index.android.bundle.meta

原生调用了assets目录下的index.android.bundle文件,先在RN端生成文件再用编译器运行即可!

猜你喜欢

转载自blog.csdn.net/hxy19971101/article/details/81415728