React native 中遇到问题(1)

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
     
     
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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
}
}

再来一次,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, // add
} = 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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值