Flipper Network Plugin无网络请求显示问题排查求助
Hey there, I spot the exact issue causing your Flipper network traffic not to show up!
The core problem is that you're creating two separate instances of NetworkFlipperPlugin: one in your MoveeApp's initFlipper() method (which gets added to the Flipper client) and another brand new one in your NetworkModule (which gets passed to the OkHttp interceptor). These two instances don't share any state, so the requests intercepted by OkHttp never reach the Flipper client you set up.
Here's how to fix it:
Store the NetworkFlipperPlugin instance in your Application class
Make the plugin instance accessible globally so your NetworkModule can reuse it instead of creating a new one:class MoveeApp : Application() { // Lazy initialize the plugin to avoid unnecessary creation in release builds val networkFlipperPlugin by lazy { NetworkFlipperPlugin() } override fun onCreate() { super.onCreate() initFlipper() } private fun initFlipper() { SoLoader.init(this, false) if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) { val flipperClient = AndroidFlipperClient.getInstance(this) flipperClient.addPlugin( InspectorFlipperPlugin( this@MoveeApp, DescriptorMapping.withDefaults() ) ) // Add the same plugin instance to Flipper client flipperClient.addPlugin(networkFlipperPlugin) flipperClient.start() } } }Reuse the existing plugin instance in NetworkModule
Inject your Application into the module, then fetch the pre-created plugin instead of instantiating a new one:@InstallIn(ApplicationComponent::class) @Module object NetworkModule { @Singleton @Provides fun provideOkHttpClient( requestInterceptor: RequestInterceptor, application: Application // Inject the Application context ): OkHttpClient = OkHttpClient.Builder() .addInterceptor(requestInterceptor) // Use the plugin instance from MoveeApp .addNetworkInterceptor(FlipperOkhttpInterceptor((application as MoveeApp).networkFlipperPlugin)) .build() }
Quick checks to ensure everything works:
- Restart your Android app and the Flipper desktop client (sometimes a fresh connection is needed)
- Double-check that the Network plugin is enabled in your Flipper desktop app
- Confirm all your Flipper dependencies (mobile + desktop) are on the same version (you're already using 0.54.0 across the board, which is good!)
After making these changes, your OkHttp requests should be intercepted and passed to the Flipper client's Network plugin, and you'll start seeing the traffic in the desktop app.
内容的提问来源于stack exchange,提问作者Şevval

