React Native for Android - Amazon Build
=======================================

This zip contains the following resources:

- Modified source code for android-jsc, downloaded from 
  https://github.com/facebook/android-jsc/archive/ff41febb87c9ea754d3122c00de64c19f00a0839.zip

- Modified source code for react-native (version 0.41.2) downloaded from 
  https://github.com/facebook/react-native/archive/v0.41.2.zip

- Unmodified ICU source code archive, downloaded from 
  https://android.googlesource.com/platform/external/icu/+archive/e25a54101b72d27b345934e1574aa314c1899969/icu4c/source.tar.gz

- Unmodified WebKit source code archive, downloaded from 
  https://builds-nightly.webkit.org/files/trunk/src/WebKit-r174650.tar.bz2
  and re-archived to only include JavaScriptCore and WTF directories which are needed for this software.

In the rest of this README file, the location where you've extracted the zip containing this file, will be referred to as
"<reactNativeAmazonRootDir>". For example, this README file on your computer is located at <reactNativeAmazonRootDir>/README.txt

Requirements
============

- 64-bit Linux. The build process has not been tested on other platforms.

- Android development environment setup (SDK + NDK).
  
  - Android SDK installation instructions can be found at https://developer.android.com/studio/index.html

  - Android NDK can be downloaded from http://dl.google.com/android/repository/android-ndk-r10e-linux-x86_64.zip
    You can find further instructions on the official page at https://developer.android.com/ndk/downloads/index.html
  
  - After completing the installations, set environment variables through your local shell to the installation paths:

    export ANDROID_SDK=/Users/your_unix_name/android-sdk
    export ANDROID_HOME=/Users/your_unix_name/android-sdk
    export ANDROID_NDK=/Users/your_unix_name/android-ndk-r10e

- "Requirements" section of android-jsc. See <reactNativeAmazonRootDir>/android-jsc/README.md for details.

- "Prerequisites" section of "Building React Native from source" document.
  See <reactNativeAmazonRootDir>/react-native/docs/AndroidBuildingFromSource.md for details.

Instructions
============

- A. Building android-jsc

  - 1. Change your directory to android-jsc.

       cd <reactNativeAmazonRootDir>/android-jsc

  - 2. Extract ICU and WebKit archives.

       ./fetch_sources.sh

  - 3. Build with Buck. This will take a while.

       buck build :android-jsc

  - 4. Create libjsc.a. While completing the build of android-jsc, this step will also move the generated artifacts into 
       react-native's dependency directories. "REACT_ANDROID_ROOT" environment variable at this step refers to the location of 
       "ReactAndroid" directory inside react-native. Assuming you are still in android-jsc directory, proceed with the command below.

       REACT_ANDROID_ROOT=../react-native/ReactAndroid ./build_archive.sh

- B. Building react-native

  - 0. Finish building of android-jsc successfully.

  - 1. Change your directory to react-native.

       cd <reactNativeAmazonRootDir>/react-native

  - 2. Build with Gradle.
    
       ./gradlew :ReactAndroid:installArchives

  - 3. You can now find the consumable Android artifact (AAR file) in the following path:
       react-native/ReactAndroid/build/outputs/aar/ReactAndroid-release.aar

- C. Using built react-native AAR in a new project.

  - 0. The last step of react-native build, in addition to creating the AAR, will also prepare 
       <reactNativeAmazonRootDir>/react-native/android directory, which you can use for your local
       Maven repository. In this section, there's a brief tutorial on how you can make use of it.

  - 1. Following the "Getting Started" tutorial of React Native, initialize a new project.
       You can find the tutorial at either http://facebook.github.io/react-native/releases/0.41/docs/getting-started.html
       or <reactNativeAmazonRootDir>/react-native/docs/GettingStarted.md

       While using React Native's command line tools, in order to initialize a new project with a specific
       version of React Native, use "--version" argument. Since the newly built React Native uses version 0.41.2,
       you can proceed with the command below.

       react-native init --version="0.41.2" AwesomeProject

  - 2. Change your directory to the newly created project.

       cd AwesomeProject

  - 3. By default, your app will use node_modules directory for the React Native Maven repository.
       In order to use the newly built AAR, modify the Gradle script as follows:

       - Modify android/build.gradle with a text editor.

       - Find the line starting with "url", and comment it out.
         Below it, add a new line, with a url pointing to the local Maven repository

         // url "$rootDir/../node_modules/react-native/android"
         url "<reactNativeAmazonRootDir>/react-native/android"

  - 4. Continue with regular app build steps. The applications created within this project will now make use of the newly built AAR.
       For example, following command will generate the debug apks for testing.

       cd android // change directory to AwesomeProject/android
       ./gradlew :app:assembleDebug
