react-native/ReactAndroid
Geoffrey Goh e730a9fdd0 Load assets from same folder as JSbundle (Android)
Summary:
https://github.com/facebook/react-native/issues/3679 was only partially fixed as the behaviour only works on iOS. This implements the same behaviour for Android. If the JSBundle was loaded from the assets folder, this will load images from the built-in resources. Else, load the image from the same folder as the JS bundle.

EDIT: For added clarity:

On iOS,
Bundle Location: 'file:///Path/To/Sample.app/main.bundle'
httpServerLocation: '/assets/module/a/'
Name: 'logo'
type: 'png'
**Resolved Asset location: '/Path/To/Sample.app/assets/module/a/logo.png'**

On Android,
Bundle Location: 'file:///sdcard/Path/To/main.bundle'
httpServerLocation: '/assets/module/a/',
name: 'logo'
type: 'png'
**Resolved Asset location: 'file:///sdcard/Path/To/drawable_mdpi/module_a_logo.png'**
Closes https://github.com/facebook/react-native/pull/4527

Reviewed By: svcscm

Differential Revision: D2788005

Pulled By: mkonicek

fb-gh-sync-id: 3f6462a7ee6370a92dd6727ac422c5de346c3ff1
2016-01-06 08:46:35 -08:00
..
libs Release React Native for Android 2015-09-14 18:13:39 +01:00
src Load assets from same folder as JSbundle (Android) 2016-01-06 08:46:35 -08:00
.npmignore Don't publish /ReactAndroid/build to npm, update version on master 2015-10-12 11:11:40 -07:00
DevExperience.md Fixed typo 2015-12-31 12:26:10 +04:00
README.md Merge pull request #2953 from j27cai/and-patch 2015-10-14 17:00:59 +01:00
build.gradle increased stability of circleCI e2e tests 2015-12-30 11:39:32 -08:00
gradle.properties Ability to run unit tests in react-android-github via gradle 2015-11-27 04:20:19 -08:00
release.gradle Release React Native for Android 2015-09-14 18:13:39 +01:00

README.md

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 installed, run android to open the Android SDK Manager.

Make sure you have the following installed:

  • Android SDK version 23 (compileSdkVersion in build.gradle)
  • SDK build tools version 23.0.1 (buildToolsVersion in build.gradle)
  • Android Support Repository >= 17 (for Android Support Library)
  • Android NDK (download & extraction instructions here)

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.

cd react-native
npm install

Building from the command line

To build the framework code:

cd react-native
./gradlew :ReactAndroid:assembleDebug

To install a snapshot version of the framework code in your local Maven repo:

./gradlew :ReactAndroid:installArchives

Running the examples

To run the UIExplorer app:

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.:

./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:

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.