From f4e085a06cb87525904de194334f800d714ac092 Mon Sep 17 00:00:00 2001 From: Martin Konicek Date: Thu, 18 Feb 2016 07:59:07 -0800 Subject: [PATCH] Clean up docs on building RN Android from source Summary:Turns out we had two guides for the same thing. Closes #6007 Reviewed By: mkonicek Differential Revision:D2949234 Ninja: oss-only fb-gh-sync-id: eda3a904ce8d8e7213a39021eb60b52449b20a43 shipit-source-id: eda3a904ce8d8e7213a39021eb60b52449b20a43 --- ReactAndroid/README.md | 100 +----------------------------- docs/AndroidBuildingFromSource.md | 11 +++- 2 files changed, 10 insertions(+), 101 deletions(-) diff --git a/ReactAndroid/README.md b/ReactAndroid/README.md index 891b008ac..08c34b992 100644 --- a/ReactAndroid/README.md +++ b/ReactAndroid/README.md @@ -1,101 +1,3 @@ # Building React Native for Android -This guide contains instructions for building the Android code and running the sample apps. - -## Supported Operating Systems - -This setup has only been tested on Mac OS so far. - -## Prerequisites - -Assuming you have the [Android SDK](https://developer.android.com/sdk/installing/index.html) installed, run `android` to open the Android SDK Manager. - -Make sure you have the following installed: - -- Android SDK version 23 (compileSdkVersion in [`build.gradle`](build.gradle)) -- SDK build tools version 23.0.1 (buildToolsVersion in [`build.gradle`](build.gradle)) -- Android Support Repository >= 17 (for Android Support Library) -- Android NDK (download & extraction instructions [here](http://developer.android.com/ndk/downloads/index.html)) - -Point Gradle to your Android SDK: either have `$ANDROID_SDK` and `$ANDROID_NDK` defined, or create a `local.properties` file in the root of your `react-native` checkout with the following contents: - - sdk.dir=absolute_path_to_android_sdk - ndk.dir=absolute_path_to_android_ndk - -Example: - - sdk.dir=/Users/your_unix_name/android-sdk-macosx - ndk.dir=/Users/your_unix_name/android-ndk/android-ndk-r10e - -## Run `npm install` - -This is needed to fetch the dependencies for the packager. - -```bash -cd react-native -npm install -``` - -## Building from the command line - -To build the framework code: - -```bash -cd react-native -./gradlew :ReactAndroid:assembleDebug -``` - -To install a snapshot version of the framework code in your local Maven repo: - -```bash -./gradlew :ReactAndroid:installArchives -``` - -## Running the examples - -To run the UIExplorer app: - -```bash -cd react-native -./gradlew :Examples:UIExplorer:android:app:installDebug -# Start the packager in a separate shell: -# Make sure you ran npm install -./packager/packager.sh -# Open UIExplorer in your emulator, Menu button -> Reload JS should work -``` - -You can run any other sample app the same way, e.g.: - -```bash -./gradlew :Examples:Movies:android:app:installDebug -``` - -## Building from Android Studio - -You'll need to do one additional step until we release the React Native Gradle plugin to Maven central. This is because Android Studio has its own local Maven repo: - - mkdir -p /Applications/Android\ Studio.app/Contents/gradle/m2repository/com/facebook/react - cp -r ~/.m2/repository/com/facebook/react/gradleplugin /Applications/Android\ Studio.app/Contents/gradle/m2repository/com/facebook/react/ - -Now, open Android Studio, click _Import Non-Android Studio project_ and find your `react-native` repo. - -In the configurations dropdown, _app_ should be selected. Click _Run_. - -## Installing the React Native .aar in your local Maven repo - -In some cases, for example when working on the `react-native-cli` it's useful to publish a snapshot version of React Native into your local Maven repo. This way, Gradle can pick it up when building projects that have a Maven dependency on React Native. - -Run: - -```bash -cd react-native-android -./gradlew :ReactAndroid:installArchives -``` - -## Troubleshooting - -Gradle build fails in `ndk-build`. See the section about `local.properties` file above. - -Gradle build fails "Could not find any version that matches com.facebook.react:gradleplugin:...". See the section about the React Native Gradle plugin above. - -Packager throws an error saying a module is not found. Try running `npm install` in the root of the repo. +See [docs on the website](https://facebook.github.io/react-native/docs/android-building-from-source.html). diff --git a/docs/AndroidBuildingFromSource.md b/docs/AndroidBuildingFromSource.md index 6a7cd37f1..5c3127464 100644 --- a/docs/AndroidBuildingFromSource.md +++ b/docs/AndroidBuildingFromSource.md @@ -76,7 +76,6 @@ project(':ReactAndroid').projectDir = new File( ... ``` - Modify your `android/app/build.gradle` to use the `:ReactAndroid` project instead of the pre-compiled library, e.g. - replace `compile 'com.facebook.react:react-native:0.16.+'` with `compile project(':ReactAndroid')`: ```gradle @@ -92,7 +91,6 @@ dependencies { ... ``` - #### 4. Making 3rd-party modules use your fork If you use 3rd-party React Native modules, you need to override their dependencies so that they don't bundle the pre-compiled library. Otherwise you'll get an error while compiling - `Error: more than one library with package name 'com.facebook.react'`. @@ -105,6 +103,11 @@ compile(project(':react-native-custom-module')) { } ``` +## Building from Android Studio + +From the Welcome screen of Android Studio choose "Import project" and select the `android` folder of your app. + +You should be able to use the _Run_ button to run your app on a device. Android Studio won't start the packager automatically, you'll need to start it by running `npm start` on the command line. ## Additional notes @@ -117,3 +120,7 @@ gradle.projectsLoaded { } } ``` + +## Troubleshooting + +Gradle build fails in `ndk-build`. See the section about `local.properties` file above.