【发布时间】:2015-10-21 08:41:03
【问题描述】:
我目前在 react native 方面有点挣扎。 我想要的是一个基于 react native 的库项目,然后我可以将它包含在我的一些应用程序中。
我尝试的第一件事是将所有基本的反应设置代码 [1] 移动到现有应用程序中的片段中。这没有任何问题。
然后我用一个空的 Activity 启动了一个全新的 Android 项目。 在这个项目中,我添加了一个新的 Android 库项目模块,它应该包含“反应原生片段”。然后我在我的根项目文件夹中初始化了 react native 项目。
我目前的项目结构是这样的:
ReactApplication
- basic files (index.android.js, index.ios.js, package.json, build.gradle, settings.gradle)
- app/ (contains the real native android app which includes the "react native fragment")
- reactlib/ (library project which contains a fragment with the code from [1])
- ios/
- node_modules/ (contains react-native)
通过npm start 启动开发服务器没有任何问题,但只要我启动 Android 应用程序,我就会得到以下 logcat 输出:
W/unknown:React(26957): Unable to dispatch keyboard events in JS as the react instance has not been attached
W/unknown:React(26957): You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' to forward the debug server's port to the device.
E/(26957): Unable to load script from assets: index.android.bundle
E/ReactNative(26957): Got JS Exception: ReferenceError: Can't find variable: require
请注意,我做了adb reverse tcp:8081 tcp:8081 的事情,但错误仍然出现。
稍后我想从 Android 库项目中创建一个 aar 并通过 maven 访问它。
我做错了什么?还是我想做的事根本不可能?
[1]https://facebook.github.io/react-native/docs/embedded-app-android.html#add-native-code
【问题讨论】:
标签: android react-native