bamlab / react-native-flipper-performance-monitor

An attempt to have a lighthouse for React Native. Flipper plugin to show a graph of the React Native performance monitor
MIT License
586 stars 17 forks source link

Error building react-native release like variant #72

Open fdrcslv opened 2 years ago

fdrcslv commented 2 years ago

Thanks for developing this plugin

I'm trying to build my react-native app running react-native run-android --variant debugtwo, "debugtwo" being a variant in my build.gradle. It should be no different from the release variant, except from react enviroment variables, which are hardcoded for debug purposes and a different app id from the release variant.

I get this error

/{MY_ROOT_DIRECTORY}/android/app/src/debugtwo/java/it/example/app/ReactNativeFlipper.java:26: error: cannot find symbol
import tech.bam.rnperformance.flipper.RNPerfMonitorPlugin

The current setup

ReactNativeFlipper.java in the "debugtwo" directory structure

I've copied the exact same structure from the regular "debug" variant, so the class file ReactNativeFlipper.java is in the correct position: android/app/src/debugtwo/java/it/example/app/ReactNativeFlipper.java

I get no errors with flipper iself or flipper plugins like CrashReporterPlugin, since i put to have flipper available in a release like build

implementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group: 'com.facebook.fbjni'
    }

implementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group: 'com.facebook.flipper'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}

implementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
    exclude group: 'com.facebook.flipper'
}

build.gradle

...
buildTypes {
    release {
                minifyEnabled enableProguardInReleaseBuilds
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
                signingConfig signingConfigs.release
            }

    debugtwo {
                initWith(buildTypes.release)
                matchingFallbacks = ['release']
            }
}
...

Something with the autolinking of the dependencies seems wrong, so i also tried manually linking like this

in android/settings.gradle

include ':react-native-flipper-performance-plugin'
project(':react-native-flipper-performance-plugin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-flipper-performance-plugin/android')

and in android/app/build.gradle:

implementation project(':react-native-flipper-performance-plugin') // add this line

I have also checked the node version used in android studio and the default on my machine with nvm current and they match (16.15.0)

Almouro commented 2 years ago

Hi @fdrcslv, thanks for posting an issue!

This is most definitely because the plugin code is only available in the debug build type (all the code is in the debug folder)

This plugin is a bit particular because I had added an actual React Native native module to make sure autolinking would work (quite ironic since it's not working in your case 😥). So to make sure the Flipper plugin code would not be added in production, that's why it's only present for the debug build type.

A quick fix could be to have a postinstall script that just does something like cp -R node_modules/react-native-flipper-performance-plugin/android/src/debug node_modules/react-native-flipper-performance-plugin/android/src/debugtwo/

I'm curious though, what's the reason for creating a debugtwo build type which is like release? 🤔

whoami-shubham commented 2 years ago

Hi @fdrcslv

in /android/settings.gradle

include ':flipper-plugin-rn-performance-android'
project(':flipper-plugin-rn-performance-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-flipper-performance-plugin/android')

and in ./android/app/build.gradle :

debugImplementation project(':flipper-plugin-rn-performance-android')

I guess this worked for me for manual linking