SB 调试真实设备
手机开启 USB 调试 之后,用 USB 链接电脑,再次运行 adb devices
一般情况下就能看到类似:
1
2
|
List
of devices attached
14ed2fcc device
|
说明你的设备已经链接上了,然而我手上的魅族却怎么也不出来。查一下 资料 很快就找到解决方案:
1
|
echo 0x2a45 > .android/adb_usb.ini
|
另外官网声明:
You must have only one device connected.
有且只能有一个设备链接,这时候再运行 react-native run-android
理论上应该就能和虚拟机一样跑起来了吧。然而真是图样图森破,Building 到 97% 又爆一个问题:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
app:installDebug
Installing APK
'app-debug.apk'
on
'm2 - 5.1'
03:
44:
04 E/
2099056020: Error
while uploading app-
debug.apk : Unknown failure
Unable
to install /path/
to/AwesomeProject/android/app/build/outputs/apk/app-
debug.apk
com.android.ddmlib.InstallException: Unable
to upload some APKs
at
com.android.ddmlib.Device.installPackages(Device.jav
a:920)
...
:app:installDebug FAILED
FAILURE: Build failed with
an exception.
* What went wron
g:
Execution failed
for task
':app:installDebug'.
>
com.android.builder.testing.api.DeviceException:
com.android.ddmlib.InstallException: Unable
to upload some APKs
...
|
React Native 真是被各路国产机坑坏了,还好 有人给出了解决方案:将 android/build.gradle
第 8 行的版本号改成 1.2.3
即可
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'
}
}
|
再来一次,App 跳出来了!然而,然而是红色的错误界面吖,无论怎么 RELOAD JS 都提示 Unable to download JS bundle
。还好 不是只有我一个遇到这个问题,按照 jinmatt 的方法 试一下:
1
2
|
adb reverse tcp:8081 tcp:8081
react-native run-android
|
这回真的好了!大幅度摇一摇手机,调出开发者菜单,我喜欢 Enable Live Relaod
,然后就来改改 index.android.js
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
var {
AppRegistry,
StyleSheet,
Text,
View,
SwitchAndroid,
} = React;
var PointsMall = React.createClass({
render:
function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React-Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Shake or press menu button for dev menu
</Text>
{/* add */}
<SwitchAndroid />
</View>
);
}
});
|
这回 App 的文字底部增加了一个 Android 的 Switch 按钮。
转载于:http://csbun.github.io/blog/2015/12/starting-react-native-with-android/