Skip to content

[ok_http] Proguard/R8 is removing OkHttp in Android release mode #1950

Description

@EchoEllet

Proguard/R8 is removing OkHttp classes when running the Android app in release mode:

java.lang.ClassNotFoundException: Didn't find class "okhttp3/OkHttpClient$Builder" on path: DexPathList[[zip file

Causing the app to crash.

Steps to reproduce:

  1. Create a new Flutter app
  2. Add ok_http depednency, create OkHttpClient and consume it
  1. Run the app using flutter run --release -d <ANDROID_DEVICE_ID_HERE>

Workarounds

Warning

These workarounds should be avoided in production.

Disabling R8 / minification fully

// android/app/build.gradle.kts

    buildTypes {
        release {
+            isMinifyEnabled = false
+            isShrinkResources = false
        }
    }
}

Test the app again: flutter run --release -d <ANDROID_DEVICE_ID_HERE>
and it works as intended.

Keep all OkHttp classes

+ -keep class okhttp3.** { *; }
+ -dontwarn okhttp3.**

Propused fix

Add android/proguard.txt file keep the Okhttp classes that are declared in jnigen.yaml.
flutter_plugin_android_lifecycle plugin (from flutter/packages) follows a similar pattern.

This way the consumers of ok_http will not need to modify their Android platform runner files, and only the necessary classes were kept without disabling minification or including all OkHttp classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions