Android library project with React Native

I am currently struggling a bit with reaction to my native language. I want this to be a library project based on the native reaction, which can then be included in some of my applications.

The first thing I tried was to move the entire base configuration code [1] to a fragment inside an existing application. This worked without problems.

Then I started a completely new Android project with an empty Activity. In this project, I added a new Android library project module, which should contain "edit your own fragment." Then I initialized the response source project in the folder with the root project.

My current project structure is as follows:

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) 

Starting the dev server via npm start works without problems, but as soon as I run the Android application, I get the output of 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 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 

Please note that I made an adb reverse tcp:8081 tcp:8081 object and the error still appears.

Later I want to create aar from the Android Library project and access it through maven.

What am I doing wrong? Or is that what I want to do is simply not possible?

[1] https://facebook.imtqy.com/react-native/docs/embedded-app-android.html#add-native-code

+7
android react-native
source share
1 answer

After debugging and testing several things, I realized that it cannot download the package file from the server when it is connected in aar.

If you add index.android.bundle to the Android resources folder, it will start working.

+3
source share

All Articles