!> Make sure you are using react-native version >= 0.51. We also recommend using npm version >= 3
-
Install
react-native-navigation
latest stable version.yarn add [email protected]
-
Add the following in
android/settings.gradle
.include ':react-native-navigation' project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')
-
Update project dependencies in
android/app/build.gradle
.android { compileSdkVersion 25 buildToolsVersion "25.0.1" ... } dependencies { compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:+" compile project(':react-native-navigation') }
-
In
MainActivity.java
it should extendcom.reactnativenavigation.controllers.SplashActivity
instead ofReactActivity
.This file can be located in
android/app/src/main/java/com/yourproject/
.import com.reactnativenavigation.controllers.SplashActivity; public class MainActivity extends SplashActivity { }
If you have any react-native related methods, you can safely delete them.
-
In
MainApplication.java
, add the followingimport com.reactnativenavigation.NavigationApplication; public class MainApplication extends NavigationApplication { @Override public boolean isDebug() { // Make sure you are using BuildConfig from your own application return BuildConfig.DEBUG; } protected List<ReactPackage> getPackages() { // Add additional packages you require here // No need to add RnnPackage and MainReactPackage return Arrays.<ReactPackage>asList( // eg. new VectorIconsPackage() ); } @Override public List<ReactPackage> createAdditionalReactPackages() { return getPackages(); } }
Also, add the following
@Override public String getJSMainModuleName() { return "index"; }
if you are using
index.js
as your entry point instead ofindex.ios.js
andindex.android.js
(it is the default since React Native 0.49).Make sure that
isDebug
andcreateAdditionalReactPackages
methods are implemented. -
Update
AndroidManifest.xml
and set android:name value to.MainApplication
<application android:name=".MainApplication" ... />