Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is it possible to make a setup example for android kotlin with network plugin? #5660

Open
twboc opened this issue Jul 26, 2024 · 1 comment

Comments

@twboc
Copy link

twboc commented Jul 26, 2024

I recently implemented flipper for ios react-native app debugging. So far I can see my network requests coming from a iPhone simulator.

Unfortunately I have not been so successful with android kotlin version. I managed to connect flipper and get logs and crashes through adb but the network plugin is not working.

It is added as part of dependencies and I initialise so the app compiles. Unfortunately I cannot see any requests. Tried different solutions but with no luck.

The error I am getting is similar to the one reported here -> Flipper requests not showing - flipper issues

This is also complicated with the fact that I am using OkHttp.

Although I have put everything in place (in my opinion) and the code complies the requests are not showing.

QUESTION: Is it possible for anyone to create a react-native example using kotlin like the one in here. Android Java Example react-native app

I asume this would be beneficial for other developers in the future.

@divyansh0908nl
Copy link

Hey @twboc ,

This worked for me

AndroidManifest.xml

<activity android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity" android:exported="true"/>

MainApplication.kt import update

import com.facebook.flipper.android.AndroidFlipperClient
import com.facebook.flipper.android.utils.FlipperUtils
import com.facebook.flipper.core.FlipperClient
import com.facebook.flipper.plugins.inspector.DescriptorMapping
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.react.modules.network.NetworkingModule
import okhttp3.OkHttpClient.Builder

Update to MainApplication.kt onCreate method

override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, false)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      load()
    }
    if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {

      val client = AndroidFlipperClient.getInstance(this)
      client.addPlugin(InspectorFlipperPlugin(this, DescriptorMapping.withDefaults()))
//      client.addPlugin(networkFlipperPlugin)
      val networkFlipperPlugin: NetworkFlipperPlugin = NetworkFlipperPlugin()
      NetworkingModule.setCustomClientBuilder(
        object : NetworkingModule.CustomClientBuilder {
          override fun apply(builder: Builder) {
            builder.addNetworkInterceptor(FlipperOkhttpInterceptor(networkFlipperPlugin))
          }
        })
      client.addPlugin(networkFlipperPlugin)
      client.start()
    }
  }

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants