Search code examples
react-nativereact-native-hermes

React native hermes dependencies from a remote host


Right now integrating hermes into a react-native app calls for including the files locally from node_modules in the following way

def hermesPath = "$rootDir/../../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")

I need to figure out a way to host these files in an s3 bucket that I already use for things like the react-native android dependencies.


Solution

  • My use-case is unique. I have created an Android activity that mounts a react-native app. I use ./gradlew assembleRelease uploadArchives to create a new version of it and I upload it to s3 using ci/cd from the directory where uploadArchives dumps the folder. The react-native node_module also has the dependencies already packaged so that sits side by side in the s3 bucket as well. The root build.gradle file of my plugin references the bucket itself to get the react-native dependencies like so

    maven {
        url "http://plugin name.s3.amazonaws.com/releases"
    }
    

    Then in the app.build.gradle within the dependencies block, implementation ('com.facebook.react:react-native:0.62.2') { force = true }

    That is referencing the uploaded react-native dependency on s3. With the upgrade to 62.2 there was an additional dependency added to a react-native app. In order to use hermes the following lines needed to be added

    def hermesPath = "$rootDir/../../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
    

    Well that doesn't work for us because, when the integrating app tries to add the android activity + bundled javascript and instantiate it, it crashes with missing hermes dependencies. The following is the error: UnsatisfiedLinkError: couldn't find DSO to load. The only way to fix this is to addq the above dependencies from a relative directory to the parent project which is not an option for us. What needed to be done is host the hermes release and debug aar files on s3. However, gradle/maven cannot consume an aar file that doesn't come with the .pom file(i think? im new to this stuff). So I posted here and @that other guy passed a very useful command.

    mvn install:install-file -Dfile=node_modules/hermes-engine/android/hermes-release.aar -DgroupId=com.hermes -DartifactId=hermes-release -Dversion=0.4.1 -Dpackaging=aar -DgeneratePom=true
    

    So basically this command creates a versioned and consumable in the way that is needed. You can do this for the debug and release version of hermes (there are two in the node_modules directory.

    Then you can upload them to s3 and the plugin can reference the dependencies without the parent app needing to reference them aswell. (The version is arbitrary)

    def jscFlavor = 'org.webkit:android-jsc:+'
    dependencies {
        def enableHermes = project.ext.react.get("enableHermes", false);
        println enableHermes
          // for RN 0.61+
        if (enableHermes) {
            debugImplementation 'com.hermes:hermes-debug:0.4.1'
            releaseImplementation 'com.hermes:hermes-release:0.4.1'
        } else {
            implementation jscFlavor
        }
    ...
    }