Okhttp: OkHttp 3.9.0 IllegalStateException with Cookies and ProGuard

Created on 5 Sep 2017  路  2Comments  路  Source: square/okhttp

Sample project: https://github.com/talklittle/TestOkHttp3.9.0

Crashes with OkHttp 3.9.0; works with OkHttp 3.8.1

Crashes with minifyEnabled true; works with minifyEnabled false

I guess ProGuard is stripping away src/main/resources/.

java.lang.IllegalStateException: Unable to load publicsuffixes.gz resource from the classpath.
       at okhttp3.internal.publicsuffix.PublicSuffixDatabase.findMatchingRule(PublicSuffixDatabase.java:120)
       at okhttp3.internal.publicsuffix.PublicSuffixDatabase.getEffectiveTldPlusOne(PublicSuffixDatabase.java:83)
       at okhttp3.Cookie.parse(Cookie.java:311)
       at okhttp3.Cookie.parse(Cookie.java:219)
       at okhttp3.Cookie.parseAll(Cookie.java:445)
       at okhttp3.internal.http.HttpHeaders.receiveHeaders(HttpHeaders.java:201)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:95)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
       at okhttp3.RealCall.execute(RealCall.java:77)
bug documentation

Most helpful comment

Worked: Proguard rule -keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase

All 2 comments

Does not work: Proguard rule -keepdirectories src/main/resources/okhttp3/**

Does not work: Copying publicsuffixes.gz into app's src/main/resources/okhttp3/internal/publicsuffix/publicsuffixes.gz, even combined with above proguard rule.

Does not work: In build.gradle:

android {
    sourceSets {
        main {
            resources.srcDirs = ['src/main/resources', 'src/main/resources/okhttp3/internal/publicsuffix']
        }
    }
}

Worked: Proguard rule -keep class okhttp3.internal.publicsuffix.PublicSuffixDatabase

Was this page helpful?
0 / 5 - 0 ratings