markdown React Native Android入门

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown React Native Android入门相关的知识,希望对你有一定的参考价值。

# Quick Start Guide

https://facebook.github.io/react-native/docs/getting-started.html#content
http://facebook.github.io/react-native/docs/android-setup.html

## Installing a bunch of deps

We're going to be use io.js because node has a lot of trouble with the `react-native` cli.

Download io.js - https://iojs.org/en/

```
brew install watchman
brew install gradle
brew install android-ndk
brew install android-sdk
sudo npm install -g react-native-cli
```

## Add SDK and NDK to your path

In your bash profile, export the android-sdk and android-ndk

```
export ANDROID_HOME=/usr/local/opt/android-sdk
export ANDROID_NDK=/usr/local/Cellar/android-ndk/r10e
```

## Running Your Own App

Go into the root of an app created using ` react-native init` and run:

```
react-native run-android
```

## Running Examples Repo on Device

```
git clone git@github.com:facebook/react-native.git
cd react-native
./gradlew :Examples:Movies:android:app:installDebug

# Start the packager in a separate shell (make sure you ran npm install):
./packager/packager.sh
```

https://www.npmjs.com/package/react-native#documentation

### Building the app (without react-native toolkit)

This isn't recommended, but the route I went down first before discovering the prior method.

```
gradle # to build
gradle assemble # to make unsigned apk
```

This will generate three files in `project/build/outputs/apk/`

```
app-debug-unaligned.apk 
app-debug.apk
app-release-unsigned.apk
```

**Gotcha's for doing it the hard way**

It might complain that you are missing some deps or build tools when trying to build or install, you can install them from the command line using:
```
sudo android update sdk --no-ui --all --filter build-tools-23.0.1
android update sdk --no-ui --filter 'platform-tools'
```

### Running unsigned/debug APK on device

* Enable USB debugging
* Ensure that your development computer can detect your device when connected via USB

```
adb -d install /build/outputs/apk/app-debug.apk
```

The -d flag specifies that you want to use the attached device (in case you also have an emulator running).

http://developer.android.com/tools/building/building-cmdline.html#RunningOnDevice

## Red screen of death?

http://stackoverflow.com/questions/32572399/react-native-android-failed-to-load-js-bundle

## React Native Modules

http://react.parts/native

## More Gotchas

See this when trying to run `react-native run-android`?

Just delete the file node_modules/react-native/node_modules/react-tools/docs/js/react.js and everything is fine.

![run-android-error](https://cloud.githubusercontent.com/assets/1843672/9090990/9fae9f34-3b6b-11e5-8b58-d91fd81b61a0.png)

https://github.com/facebook/react-native/issues/2234#issuecomment-139800452

以上是关于markdown React Native Android入门的主要内容,如果未能解决你的问题,请参考以下文章

markdown React Native中的numberOfLines

markdown 我的React Native开发环境

markdown React Native Bridging Cheatsheet

markdown React Native Android入门

markdown 安装React Native Debugger(独立)

markdown React Native和FIrebase动态链接