ARTICLE AD BOX
I am currently maintaining a legacy standalone android project that uses a react native module for a particular feature in the app. The current production version of react native used in the app is 0.63.2 which is insanely old and not found anywhere in the react native npm. So we decided to upgrade the version for 2 main reasons:
Google's 16kb paging requirement keeps getting flagged on the .so files related to the react native module.
To update it so that the above issue and any futuristic issues are addressed.
The first challenge to solve was that the previous developers added all the react native libraries and dependencies as .aar files inside the standalone project. This was perhaps before autolinking was introduced. But with the newer versions, we cannot get .aar files from what I read.This is the format they have used in my project:

I followed the methods suggested in the following sites:
React native as a submodule
Upgrade React native in a brownfield application
Integrate React native
But unfortunately I could not get my project to work. Keeps showing autolinking issues.
Then I referred the official Facebook link but they are asking us to put everything into an /android folder.
So what I tried to do is I first created a new RN project inside my standalone project and named it rnandroid. The project was created with all necessary files such as node_modules, package.json, yarn etc.
What I did next is I copied all the gradle setup into my standalone project files and then moved all the .js and node_modules files to my standalone app's root and adjusted the paths in the gradle files accordingly.
standalone app root/build.gradle:
dependencies { <other existing dependencies> classpath("com.facebook.react:react-native-gradle-plugin") }standalone app's app/build.gradle
plugins { id "com.android.application" id "org.jetbrains.kotlin.android" id "org.jetbrains.kotlin.kapt" id "org.jetbrains.kotlin.plugin.parcelize" id "com.google.gms.google-services" id "com.google.firebase.crashlytics" id "com.google.firebase.firebase-perf" id "com.facebook.react" } /** * This is the configuration block to customize your React Native Android app. * By default you don't need to apply any configuration, just uncomment the lines you need. */ react { /* Folders */ // The root of your project, i.e. where "package.json" lives. Default is '../..' root = rootDir // The folder where the react-native NPM package is. Default is ../../node_modules/react-native reactNativeDir = file("$rootDir/node_modules/react-native") // The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen codegenDir = file("$rootDir/node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js cliFile = file("$rootDir/node_modules/react-native/cli.js") /* Variants */ // The list of variants to that are debuggable. For those we're going to // skip the bundling of the JS bundle and the assets. By default is just 'debug'. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. // debuggableVariants = ["liteDebug", "prodDebug"] /* Bundling */ // A list containing the node command and its flags. Default is just 'node'. // nodeExecutableAndArgs = ["node"] // // The command to run when bundling. By default is 'bundle' // bundleCommand = "ram-bundle" // // The path to the CLI configuration file. Default is empty. // bundleConfig = file(../rn-cli.config.js) // // The name of the generated asset file containing your JS bundle // bundleAssetName = "MyApplication.android.bundle" // // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' // entryFile = file("../js/MyApplication.android.js") // // A list of extra flags to pass to the 'bundle' commands. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle // extraPackagerArgs = [] /* Hermes Commands */ // The hermes compiler command to run. By default it is 'hermesc' // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" // // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // hermesFlags = ["-O", "-output-source-map"] /* Autolinking */ autolinkLibrariesWithApp() } dependencies { <other dependencies> implementation("com.facebook.react:react-android") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } }After all this setup, I keep running into issues like :
autolinkLibrariesFromCommand: process npx @react-native-community/cli config exited with error code: 1
this is my react-native.config.js
module.exports = { project: { android: { packageName: '<package name>', sourceDir: './app' }, }, assets: ['./assets/fonts/'], };Upon running npx @react-native-community/cli config, I got this output
{ "root": "/Users/kaarthick/Projects/ezl-android", "reactNativePath": "/<path-to-project>/node_modules/react-native", "reactNativeVersion": "0.76", "dependencies": {}, ..... "project": { "ios": null, "android": { "sourceDir": "<path_to_project>/app", "appName": "", "packageName": "<packagename>", "applicationId": "<appId>", "mainActivity": ".SplashActivity", "assets": [] } }My biggest concern is that since it is a legacy project, I am worried that changing a lot for the react native setup might break it completely. What would be the best approach to integrate/ embed React native into a standalone native android project?
