react-native-android-test

react-native Android 真机测试

我并不喜欢吐槽,但系理论上虚拟机上跑起的程序到真机不可以开飞机?然而:( 我还是图样图森破

———————————————————————————————————————————————————————————————————————吐槽分割线

真机测试遇到的bug

1.

1
2
3
4
5
6
7
8
:app:installDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unable to upload some APKs
...

解决方案: 将{YourProduct}\android\build.gradle 改成

1
2
3
4
5
6
7
8
9
10
11
12
13
...
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
...

2.解决上述问题再跑react-native run-android,红色error界面 提示Unable to download JS bundle
解决方案:

1
2
adb reverse tcp:8081 tcp:8081
react-native run-android

3.测试界面出来了,与虚拟机的一模一样,弹出开发者菜单

1
2
#摇一摇:) 使劲摇 or
adb shell input keyevent 82

点击Enable Hot Reloading,改改index.android.js代码,红色error界面
解决方案:

  • 查出本机内网ip百度方法
  • 弹出开发者菜单->Dev Settings->Debug server host & port for device
  • 输入本机ip:8081

真机测试结果

finish