androidreact-nativeandroid-build-type

react native - android - build types/variants


I am trying to add another build type to the android version of our app to get staging in. Please note that the other to variants are working fine, which makes me believe actually there is no package missing, but somehow the connection to that new variant is missing.

buildTypes {
        debug {
            applicationIdSuffix ".myapp"
            signingConfig signingConfigs.debug
            minifyEnabled false
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            matchingFallbacks = ['debug', 'release']
            if (nativeArchitectures) {
                ndk {
                    abiFilters nativeArchitectures.split(',')
                }
            }
        }
stage {

            initWith debug
            applicationIdSuffix ".myapp.stage"
        
        }
release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"      applicationIdSuffix ".myapp.prod"
            debuggable false
   
        }

The build for stage runs through and is completed, but the app crashes on start without loading metro and the following error:

2022-08-30 19:56:07.883 8232-8232/com.ourapp.stage E/SoLoader: couldn't find DSO to load: libjscexecutor.so

I also can see that in the build variants the introduced stage is only applied to the app itself not the modules (not sure whether this is a hint):

enter image description here


Solution

  • okay, we found that if we include the following in the app/build.gradle:

    project.ext.react = [
        enableHermes: true,  // clean and rebuild if changing
        devDisabledInStage: false,
        bundleInStage: true,
    ]
    

    and then:

    stageImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.fbjni'
        }
    
        stageImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
            exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
    
        stageImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
        }
    
        if (enableHermes) {
            def hermesPath = "../../node_modules/hermes-engine/android/";
            debugImplementation files(hermesPath + "hermes-debug.aar")    
            stageImplementation files(hermesPath + "hermes-debug.aar")
            releaseImplementation files(hermesPath + "hermes-release.aar")
        } else {
            implementation jscFlavor
        }
    }
    

    all the modules get also build and we can run our own build variant (not using flavours). I am not sure I fully understand all that is going on, but at least in conjunction with react-native-config we can now run the three stages that point at different backend environments.