react-native-navigation的迁移库

installation-android.md 2.0KB

Android Installation

First add react-native-navigation as an npm dependency: yarn add react-native-navigation


  • Make sure you are using react-native version 0.43 or above
  1. Add the following to your settings.gradle file located in the android folder:

    include ':react-native-navigation'
    project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')
    
  2. Update project dependencies in build.gradle under app folder.

    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')
    }
    
  3. Your MainActivity should extend com.reactnativenavigation.controllers.SplashActivity instead of ReactActivity. If you have any react-native related methods in your MainActivity you can safely delete them.

  4. Update the MainApplication file and update the Application element in AndroidManifest.xml

    import com.reactnativenavigation.NavigationApplication;
        
    public class MainApplication extends NavigationApplication {
        
    }
    
    <application
        android:name=".MainApplication"
        ...
        />
    
  5. Implement isDebug and createAdditionalReactPackages methods

    import com.reactnativenavigation.NavigationApplication;
        
    public class MyApplication extends NavigationApplication {
     
        @Override
        public boolean isDebug() {
            // Make sure you are using BuildConfig from your own application
            return BuildConfig.DEBUG;
        }
    
        @Override
        public List<ReactPackage> createAdditionalReactPackages() {
            // Add the packages you require here.
            // No need to add RnnPackage and MainReactPackage
            return null;
        }
    }
    
  6. Run react-native start