facebook / flipper

A desktop debugging platform for mobile developers.
https://fbflipper.com/
MIT License
13.32k stars 954 forks source link

Android: Duplicate Fbjni-java classes in LeakCanary Plugin implementation #3597

Open GordonShinozaki opened 2 years ago

GordonShinozaki commented 2 years ago

🐛 Bug Report

After running the build for android for my react native app, I get this error

To Reproduce

  1. Implement LeakCanary Plugin using this official documentation https://fbflipper.com/docs/setup/plugins/leak-canary/
  2. Change the code a little bit for Java, since we are using react native
  3. Please note that there we are also using other plugins, so this is what the depencies look like in build.gradle (Flipper_Version is 0.54.0)
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-leakcanary2-plugin:0.141.0") 
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }
  4. run yarn && yarn android

Environment

  1. I'm using a Big Sur MacOS on the 2015 Macbook pro, but this error shows for any device
  2. Same Error for any Flipper_Version variable (even later versions)
  3. Running on Android SDK 30
  4. classpath("com.android.tools.build:gradle:4.1.0")
  5. React Native 0.64.3
  6. Flipper Desktop 0.139.0

Things I've Tried So Far

  1. Changing Flipper_Versions
  2. Adding
    {
      exclude group:'com.facebook.fbjni'
    }

    to the leakcanary debugimplementation code (causes LeakCanary not defined / found error)

trigonometric-act commented 2 years ago

Still same problem with flipper desktop 0.147.1

trigonometric-act commented 2 years ago

@GordonShinozaki have you find any workaround?

Ali-Sheharyar commented 2 years ago

@GordonShinozaki @trigonometric-act Any solution? please share

trigonometric-act commented 2 years ago

@Ali-Sheharyar no solution yet, if you want an advice search for a workaround outside flipper to find leaks, for example xcode tools or chrome tools. I wasted too many hours diving in flipper without results when its supposed to be the optimal tool for developing react native

YadongChen commented 1 year ago

react-native 0.68.x + flipper 0.162.0

This setting works for me (这样的设置对我生效):

android/app/build.gradle


dependencies {
    ...
    implementation "com.facebook.react:react-native:+"

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

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

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

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

    // https://github.com/facebook/flipper/blob/v0.162.0/build.gradle#L103
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
    ...
}

android {
    ...
    packagingOptions {
        jniLibs {
            pickFirsts += ['**/libc++_shared.so']
        }
        // pickFirst 'lib/x86/libc++_shared.so'
        // pickFirst 'lib/x86_64/libjsc.so'
        // pickFirst 'lib/arm64-v8a/libjsc.so'
        // pickFirst 'lib/arm64-v8a/libc++_shared.so'
        // pickFirst 'lib/x86_64/libc++_shared.so'
        // pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    }
    ...
}