Update Android Guide for Integration With Existing Apps

Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

I was trying to follow the instruction on http://facebook.github.io/react-native/docs/integration-with-existing-apps.html to integrate react native into existing android app, but failed. After hours of google/stackoverflow, I finally get it running. I am submitting this pr the list the diffs in the guide so that other developer won't fell into the same issues.

- create an example android project
- follow the guide in the pr to integrate react-native into the example android project
- make sure it runs without error
Closes https://github.com/facebook/react-native/pull/15813

Differential Revision: D5767573

Pulled By: hramos

fbshipit-source-id: 805165a64b6db2aa2de936ad8f6a8a3d2fedd7c4
This commit is contained in:
GingerBear 2017-09-05 10:51:51 -07:00 committed by Facebook Github Bot
parent 5a3828d299
commit 75850b9014
1 changed files with 6 additions and 3 deletions

View File

@ -157,9 +157,11 @@ Go to the root directory for your project and create a new `package.json` file w
Next, you will install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the root directory for your project and type the following commands: Next, you will install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the root directory for your project and type the following commands:
``` ```
$ npm install --save react react-native $ npm install --save react@16.0.0-beta.5 react-native
``` ```
> Make sure you use the same React version as specified in the [React Native package.json](https://github.com/facebook/react-native/blob/master/package.json) for your release. This will only be necessary as long as React Native depends on a pre-release version of React.
This will create a new `/node_modules` folder in your project's root directory. This folder stores all the JavaScript dependencies required to build your project. This will create a new `/node_modules` folder in your project's root directory. This folder stores all the JavaScript dependencies required to build your project.
<block class="objc swift" /> <block class="objc swift" />
@ -542,6 +544,7 @@ Add the React Native dependency to your app's `build.gradle` file:
``` ```
dependencies { dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
... ...
compile "com.facebook.react:react-native:+" // From node_modules. compile "com.facebook.react:react-native:+" // From node_modules.
} }
@ -557,7 +560,7 @@ allprojects {
... ...
maven { maven {
// All of React Native (JS, Android binaries) is installed from npm // All of React Native (JS, Android binaries) is installed from npm
url "$rootDir/node_modules/react-native/android" url "$rootDir/../node_modules/react-native/android"
} }
} }
... ...
@ -738,7 +741,7 @@ protected void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mReactInstanceManager != null) { if (mReactInstanceManager != null) {
mReactInstanceManager.onHostDestroy(); mReactInstanceManager.onHostDestroy(this);
} }
} }
``` ```