Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
集成到现有的Android应用程序中,获取错误null不是一个对象(评估';RNGestureHandlerModule.Direction)_Android_React Native_React Navigation - Fatal编程技术网

集成到现有的Android应用程序中,获取错误null不是一个对象(评估';RNGestureHandlerModule.Direction)

集成到现有的Android应用程序中,获取错误null不是一个对象(评估';RNGestureHandlerModule.Direction),android,react-native,react-navigation,Android,React Native,React Navigation,我正在尝试将React Native集成到现有的本机应用程序中。我已经成功地使用CocoaPods和react native link与iOS集成。对于Android,我得到以下错误:- null is not an object ( evaluating 'RNGestureHandlerModule.Direction) 我正在学习Android的FB教程 my package.json依赖项部分:- "dependencies": { "react": "^16.8.4",

我正在尝试将React Native集成到现有的本机应用程序中。我已经成功地使用CocoaPods和react native link与iOS集成。对于Android,我得到以下错误:-

null is not an object ( evaluating 'RNGestureHandlerModule.Direction)
我正在学习Android的FB教程

my package.json依赖项部分:-

"dependencies": {
    "react": "^16.8.4",
    "react-native": "^0.59.1",
    "react-native-gesture-handler": "^1.1.0",
    "react-navigation": "^3.5.0",
    "react-redux": "^6.0.1"
  }
我已经按照指南链接了RNGH。我认为解决方法与。但在《FBs与现有本机应用程序集成指南》中,他们没有关于如何与具有本机代码的库集成的指南

ReactMainActivity.java

public class ReactMainActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private ReactInstanceManager mReactInstanceManager;
    private final int OVERLAY_PERMISSION_REQ_CODE = 10;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mReactRootView = new RNGestureHandlerEnabledRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setCurrentActivity(this)
                .setBundleAssetName("index.android.bundle")
                .setJSMainModulePath("index")
                .setDefaultHardwareBackBtnHandler(this)
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        // The string here (e.g. "MyReactNativeApp") has to match the
        // string in AppRegistry.registerComponent() in index.js
        mReactRootView.startReactApplication(mReactInstanceManager,
                "ReactApp", null);

        setContentView(mReactRootView);

        if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostPause(this);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostResume(this, this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostDestroy(this);
        }
        if (mReactRootView != null) {
            mReactRootView.unmountReactApplication();
        }
    }

    @Override
    public void onBackPressed() {
        if (mReactInstanceManager != null) {
            mReactInstanceManager.onBackPressed();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
            mReactInstanceManager.showDevOptionsDialog();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!Settings.canDrawOverlays(this)) {
                    Toast.makeText(this, "Please enable System overlay display from settings", Toast.LENGTH_LONG).show();
                }
            }
        }
        mReactInstanceManager.onActivityResult(this, requestCode, resultCode, data);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}
public class App extends MultiDexApplication implements ReactApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, false);
    }

    @Override
    public ReactNativeHost getReactNativeHost() {
        return new ReactNativeHost(this) {
            @Override
            public boolean getUseDeveloperSupport() {
                return BuildConfig.DEBUG;
            }

            @Override
            protected List<ReactPackage> getPackages() {
                return Arrays.asList(new MainReactPackage(), new RNGestureHandlerPackage());
            }
        };
    }
}
Application.java

public class ReactMainActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private ReactInstanceManager mReactInstanceManager;
    private final int OVERLAY_PERMISSION_REQ_CODE = 10;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mReactRootView = new RNGestureHandlerEnabledRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setCurrentActivity(this)
                .setBundleAssetName("index.android.bundle")
                .setJSMainModulePath("index")
                .setDefaultHardwareBackBtnHandler(this)
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        // The string here (e.g. "MyReactNativeApp") has to match the
        // string in AppRegistry.registerComponent() in index.js
        mReactRootView.startReactApplication(mReactInstanceManager,
                "ReactApp", null);

        setContentView(mReactRootView);

        if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostPause(this);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostResume(this, this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostDestroy(this);
        }
        if (mReactRootView != null) {
            mReactRootView.unmountReactApplication();
        }
    }

    @Override
    public void onBackPressed() {
        if (mReactInstanceManager != null) {
            mReactInstanceManager.onBackPressed();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
            mReactInstanceManager.showDevOptionsDialog();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!Settings.canDrawOverlays(this)) {
                    Toast.makeText(this, "Please enable System overlay display from settings", Toast.LENGTH_LONG).show();
                }
            }
        }
        mReactInstanceManager.onActivityResult(this, requestCode, resultCode, data);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}
public class App extends MultiDexApplication implements ReactApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, false);
    }

    @Override
    public ReactNativeHost getReactNativeHost() {
        return new ReactNativeHost(this) {
            @Override
            public boolean getUseDeveloperSupport() {
                return BuildConfig.DEBUG;
            }

            @Override
            protected List<ReactPackage> getPackages() {
                return Arrays.asList(new MainReactPackage(), new RNGestureHandlerPackage());
            }
        };
    }
}
公共类应用程序扩展了多索引应用程序{
@凌驾
public void onCreate(){
super.onCreate();
SoLoader.init(this,false);
}
@凌驾
公共ReactNativeHost getReactNativeHost(){
返回新的ReactNativeHost(此){
@凌驾
公共布尔getUseDeveloperSupport(){
返回BuildConfig.DEBUG;
}
@凌驾
受保护的列表getPackages(){
返回Arrays.asList(新的MainReactPackage(),新的RNGestureHandlerPackage());
}
};
}
}
我可以确定的问题是,在实现
ReactNativeApplication
的应用程序类中,我的
应用程序::getReactNativeHost()
从未被触发,因此我认为本机链接失败


在此方面的任何帮助都将不胜感激。

这是因为版本3有问题。+我建议使用版本2.18.2

降级的步骤:

npm uninstall react-navigation

npm install react-navigation@2.18.2 --save
启动包:

react-native start --reset-cache
运行应用程序:

react-native run-android

这是因为版本3有问题。+我建议使用版本2.18.2

降级的步骤:

npm uninstall react-navigation

npm install react-navigation@2.18.2 --save
启动包:

react-native start --reset-cache
运行应用程序:

react-native run-android