有没有办法让我的反应原生代码保存在一个单独的文件夹中,并且可以被Android和iOS项目使用?从共享的JS文件夹运行Android的本地代码
我目前有一个适用于iOS和Android的应用程序。我需要为应用程序使用react-native,并且遇到一些问题。我有一个3文件夹结构来完成这个:android,ios和js。目前,我有iOS项目正常工作,但Android项目是麻烦进来的地方。当我在模拟器或设备上运行Android应用程序,我得到错误Could not connect to development server。
我对我的活动设置是这样的:
reactRootView = new ReactRootView(this);
reactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(true)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
reactRootView.startReactApplication(reactInstanceManager, "SimpleApp", null);
setContentView(reactRootView);
当我运行这一点,错误窗口指示它无法连接到服务器,这是比我的本地主机(计算机),一个完全不同的IP地址。
我试过在设备上运行,并执行了adb reverse命令,但结果是一样的。
我也尝试添加:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
preferences.edit().putString("debug_http_host", "localhost:8081").apply();
但是,这仍然导致同样的错误。
2017-02-02
macandyp