okhttp: Unable to load publicsuffixes.gz resource from the classpath on minified build

First of all, thank you for maintaining this great library!

After upgrading a third party SDK (OneTrust) in our app, we ran into this crash:

java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath.

The crash only occurs in minified release builds.

It does not come from the 3rd party SDK, but rather from our own code that uses OkHttp. But it only happened after upgrading the other SDK.

After de-obfuscating the stacktrace we determined it’s coming from here:

java.lang.IllegalStateException Unable to load publicsuffixes.gz resource from the classpath.
    okhttp3.internal.publicsuffix.PublicSuffixDatabase.findMatchingRule (PublicSuffixDatabase.kt:110)
    okhttp3.internal.publicsuffix.PublicSuffixDatabase.getEffectiveTldPlusOne (PublicSuffixDatabase.kt:72)

Inside PublicSuffixDatabase.findMatchingRule:110, we find that this is what’s throwing the error:

check(::publicSuffixListBytes.isInitialized) {
    "Unable to load $PUBLIC_SUFFIX_RESOURCE resource from the classpath."
}

We attempted several changes to our R8 setup, but we weren’t able to fix the crash. Here are some of our findings and things we tried:

  • Turning off minifyEnabled made the crash go away
  • We built a debug version of the app with minification enabled, but the crash didn’t repro.
  • Turning off shrinkResources had no impact, it still crashed
  • Forcing okhttp version in gradle to 4.12.0 also did not help
  • Inspected the output of ./gradlew app:dependencies, but did not see OneTrust pulling in any other okhttp versions
  • Reached out to OneTrust but they had never seen this before
  • Inspected the minified release APK and saw that the publicsuffixes.gz file is there, so our hypothesis is that the file isn’t missing or renamed, but something with being able to access it
  • We loaded the proguard mappings into Android Studio’s APK analyzer and validated that PublicSuffixDatabase is there and looks right. We noticed some of the functions come from PublicSuffixDatabase$Companion, so we made sure to keep everything there too.
  • We tried adding these rules to our proguard config, but they didn’t work
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz
-adaptresourcefilenames okhttp3/internal/publicsuffix/publicsuffixes.gz
-keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase { *; }
-keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase$Companion { *; }

At this point I’m pretty stumped. I thought it could be a bug with OkHttp missing some kind of keep rules or permissions with locating the file, but I don’t know.

Thanks for your help & attention to this issue!

OkHttp version: 4.12.0 Android Gradle Plugin version: 8.6.0 (also occurs with 8.5.2)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19

Most upvoted comments

Thanks for your help!

We figured out the issue - this happened because of this in our Proguard file:

-repackageclasses ''

It turns out the old version of the OneTrust SDK was exposing many broad Proguard rules that our build was absorbing, including -keeppackagenames, which overrode the effects of -repackageclasses. Once we updated it, those rules went away, and our code was getting repackaged in a way that broke OkHttp.

The solution was to remove -repackageclasses from our app.

I solved by using

-repackageclasses 'okhttp3'

along with

-keep class okhttp3.internal.publicsuffix.** { *; }
-keepnames class okhttp3.internal.publicsuffix.** { *; }
-keeppackagenames okhttp3.**

As I only have the OkHttp3 resources, I had no problem with other packages.

It really helped to me. Thanks

Can you raise a bug on the onetrust sdk to advise them?

Thanks for the update