react-native-restart包错误

时间:2017-06-09 13:10:07

标签: android react-native package restart

尝试使用此程序包时出现以下错误:https://github.com/avishayil/react-native-restart

enter image description here

MainApplication.java:

package com.app;

import android.support.annotation.Nullable;

import com.avishayil.rnrestart.ReactNativeRestartPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.reactnativenavigation.NavigationApplication;
import com.avishayil.rnrestart.ReactNativeRestartPackage;

import java.util.Arrays;
import java.util.List;

import io.realm.react.RealmReactPackage;

public class MainApplication extends NavigationApplication {
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean isDebug() {
            return BuildConfig.DEBUG;
        }

        @Nullable
        @Override
        public List<ReactPackage> createAdditionalReactPackages() {
            return Arrays.<ReactPackage>asList(
                    new RealmReactPackage(),
                    new ReactNativeRestartPackage()
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

build.gradle:

dependencies {
    compile project(':realm')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile project(':react-native-navigation')
    compile project(':realm')
    compile project(':react-native-restart')
}

settings.gradle:

rootProject.name = 'App'
include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')

include ':app'

include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')

include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')

在这里我如何在我的代码中使用它:

import RNRestart from 'react-native-restart';

export default class ClassName extends Component{
...

render() {
    return (
      <View style={styles.container} accessible={true}>
          <TouchableOpacity onPress = {() => this.onPressButton()}
            <Text style={styles.button}> RESTART </Text>
          </TouchableOpacity>
      </View>
    );
  }

  onPressButton(){
    RNRestart.Restart();
  }
}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

使用自动安装解决了我的pb,请参阅github repo