React native 开发遇到的一些坑

 


ReactNative 报错或使用AndroidStaudio打包出来的安装包不是新数据:unable to load script from assets 'index.android.bundl

解决方法:

在项目根目录下运行:

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

 

   (http://www.open-open.com/lib/view/open1477469117948.html)

  > **问题1:开启悬浮框权限;**

  > **问题2:Could not get BatchedBridge, make sure your bundle is packaged correctly**

  > 解决方案:在终端中,进入到项目的根目录,执行下面这段命令行:

  > `react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/`

  > 运行之前,需要确保`android/app/src/main/`目录下有`assets`文件夹,如果没有,手动创建之~,再运行上面的命令;

  >**问题4: run-Android时候报错unable to load script from assets 'index.android.bundl

  > 解决方案:1 首先进入\android\app\src\main 新建assets文件夹

        2. 然后在根目录cmd运行如下命令:

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

6666666666666666入坑指南.note  > **问题3:could not connect to development server**

  > 解决方案:晃动手机,唤起设置属性窗口,点击“Dev settings”,再点击Debuug server host 出现设置ip地址窗口,填写Ip地址和端口号8081,例如`192.168.1.111:8081`

 

 

错误:

Command `run-android` unrecognized. Make sure that you have run `npm install` an d that you are inside a react-native project.

解决方法:

1.检查cmd运转路径是否正确.

npm i -g npm

 

错误:

the development server returned response error code:500

解决方法:

错误: 找不到 index.android.js文件 code:500

解决方法: 移除文件中的 watchman和配置的对应的path路径,若还不行就重启电脑.

错误:Could not create ADB Bridge

解决方法: 1.adb kill-server 检查adb

2.adb start-server 重启adb

错误:

Could not connect to development server

解决方法:

错误:

unable to connect with remote debugger Timeout while connecting to remote debugger

无法连接远程调试器时与远程调试器超时连接

解决方法:

断掉数据线,重新连接数据线,重新启动运行命令.

 

错误

Cannot find module 'metro-bundler/src/lib/formatBanner'

reactError: Cannot find module 'graceful-fs'

解决方法:

删除node_modules,并yarn install能解决问题

错误

解决方法:

安装 google-support

缺陷:

* What went wrong:

A problem occurred configuring project ':app'.

> Could not resolve all dependencies for configuration ':app:_debugApk'.

> A problem occurred configuring project ':react-native-image-crop-picker'.

> Failed to find Build Tools revision 27.0.0

解决方法:

C:\Program Files (x86)\Android\android-sdk 下 的 SDK Manager.exe 右键以管理员运行安装 27.0.0.

问题

Execution failed for task ':app:prepareHaierLandAppReactNativeImagePickerUnspecifiedLibrary'.

> Could not expand ZIP 'C:\Users\wny\Desktop\app3\trunk\HaierLandApp\node_modules\react-native-image-picker\android\build\outputs\aar\react-nat

ive-image-picker-release.aar'.

方法:

cd android && gradlew clean && cd .. && react-native run-android

 

 

问题:org.gradle.wrapper.GradleWrapperMain找不到或无法加载主类

解决方法:

android>gradle>wrapper中的两文件夹更换一个好项目的包.(gradle-wrapper.jar和gradle-wrapper.properties)

问题

What went wrong:

xecution failed for task ':app:prepareHaie

ecifiedLibrary'.

Could not expand ZIP 'D:\1\HaierLandApp\n

cker\android\build\outputs\aar\react-nativ

 

Try:

un with --stacktrace option to get the sta

解决方法 react-native link react-native-image-crop-picker

问题

native module pickerModule tried to override PickerModule for module name imageCropPicker if this was your intention set canOverrideExistingModule=true

 

方法 https://blog.csdn.net/qq_34057640/article/details/71082605

这个是Project\android\app\src\main\java\com\project\MainApplication.java里面

protected List getPackages() { return Arrays.asList( new MainReactPackage(),

new MainReactPackage(),(删掉一个) VectorIconsPackage() , new VectorIconsPackage() ); }

当中VectorIconsPackage重复了,(一开始是手写进去的,可能是重新编译的时候会又自动加进去一次),删除一个就可以了。

 

错误

Could not run adb reverse: Command failed: C:\Program Files (x86)\Android\android-sdk/platform-tools/adb -s 127.0.0.1:62001 reverse tcp:8081 tcp:8081

解决方法:

模拟器添加ip和端口号

错误:

java.io.IOException: Could not delete path 'C:\Users\Administrator\AndroidStudioProjects\SuperMarket

方法:

cd android

gradlew clean

错误

React native version mismatch.

JavaScrip version:0.51.1

Native version:0.55.3

解决方法

android/app/build.gradle像这样在文件中强制React Native版本compile ("com.facebook.react:react-native:0.51.1") { force = true }。

错误:

Malformed calls from JS: field sizes are different.

 

解决方法:

把 this.setStarte({

这里面的名字不能带is ,如:

isabbbb:"55"

})

错误:

application haerLandApp not been registered

未申请注册

解决方法:关闭编辑器(有可能你同时在运行一个以上的程序http://blog.sina.com.cn/s/blog_a46b2a7d0102webl.html)

问题:

Failed to find Build Tools revision 26.0.2

解决方法:

1.进入android-sdk安装路径(C:\Program Files (x86)\Android\android-sdk)文件夹

2. 右击以管理员身份运行 SDK Manager.exe文件,在里面把缺少的26.0.2安装一下就ok

 

错误:

u.notifyJSDidLoad

解决方法:https://www.aliyun.com/jiaocheng/977379.html?spm=5176.100033.2.14.e6yy1b

// 在收到点击事件之前调用此接口if(Platform.OS === 'android'){ //notifyJSDidLoad仅安卓有此方法 // JPushModule.notifyJSDidLoad((resultCode) => { // if (resultCode === 0) {} // }) //官网给的上面这种会报cb方法undefined错误 JPushModule.notifyJSDidLoad(resultCode=>console.log(resultCode)) //这样用不会报错,当然还有其他不会报错的写法。}

错误:

[SDK Patch Applier v4, Google Repository].

 

解决方法:打开C:\Program Files (x86)\Android\android-sdk,右键以管理员运行"SDK Manager.exe",安装Google Repository

 

问题:

解决-React-Native: Android project not found. Maybe run react-native android first?

  • 打开终端,进入到项目的根目录
  • 执行命令 react-native upgrade
  • 根据提示一直输入y,回车。
  • 重新输入命令react-native run-android

错误:

Could not find com.android.support:multidex:1.0.2.

解决方法:在android\build.gradle 里添加 google()

repositories {

jcenter()

google()

}

dependencies {

classpath 'com.android.tools.build:gradle:3.1.2'

 

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

 

allprojects {

repositories {

mavenLocal()

jcenter()

google()

maven {

// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm

url "$rootDir/../node_modules/react-native/android"

}

}

 

 

 

你可能感兴趣的:(React native 开发遇到的一些坑)