React native 中遇到问题(1)

前端之家收集整理的这篇文章主要介绍了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 haveonly 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: 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 的方法试一下:

     
     
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 @H_528_404@style={styles.container}>
<Text @H_528_404@style={styles.welcome}>
Welcome to React-Native!
</Text>
{styles.instructions}>
To get started,edit index.android.js
{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/

原文链接:https://www.f2er.com/react/305591.html

猜你在找的React相关文章