Guardsquare / proguard

ProGuard, Java optimizer and obfuscator
https://www.guardsquare.com/en/products/proguard
GNU General Public License v2.0
2.87k stars 411 forks source link

MinifyEnabled causing ktor with okhttp client to fail silently under gradle plugin 4.0.0 #71

Open Sheng-Xuan opened 4 years ago

Sheng-Xuan commented 4 years ago

I have a project with a network module that use ktor with okhttp client. After I upgrade gradle plugin to 4.0.0. I found that my project can't call some urls under release version with obfuscation on.

There are quite some potential areas that may cause this issue. I have posted details in an issue to ktor issue tracker. https://youtrack.jetbrains.com/issue/KTOR-946

Since there are quite some parties may cause this issue, I ask here to see if there is any clue.

Ktor 1.3.2 &1.4.0 both did not work com.android.tools.build:gradle:4.0.0 kotlin : 1.3.72 & 1.4.0 both did not work

Also tried to upgrade proguard to 7.0.0, and updating the rules that keep all relevant libraries like okhttp, ktor, coroutine, reflection, did not work.

How to replicate: minifyEnabled = true and debugale = false.

    private val client = HttpClient(OkHttp) {
        engine {
            this.config {
                dispatcher(callDispatcher)
                retryOnConnectionFailure(true)
                callTimeout(330, TimeUnit.SECONDS)
                connectTimeout(330, TimeUnit.SECONDS)
                writeTimeout(0, TimeUnit.SECONDS)
                readTimeout(0, TimeUnit.SECONDS)
                build()
            }
        }
        expectSuccess = true
    }
    suspend fun getJson(url) {
        client.request<HttpStatement>(url).execute { response: HttpResponse ->
             // Can't reach here, no error thrown
         }
        // Code here will be executed
    }

The url is under my companies' domain, strangely if I replace the url with some aws path (i.e. xxxx.amazonaws.com/xxxx), I could receive the response. I added an interceptor, the headers and url are correct, I can open that url in browser, just no response in the app.

Under release build, it will work if:

change com.android.tools.build:gradle:4.0.0 to com.android.tools.build:gradle:3.6.4 or lower or use Android engine. i.e. HttpClient(Android)' Under debug mode the code works fine with any url.

Have being debugging for quite some time.

Thanks for you help!

EricLafortune commented 4 years ago

That's hard to say, especially if it works with a different URL and with a different Gradle. You can try narrowing down any problem in ProGuard with

-dontshrink
-dontoptimize
-dontobfuscate

It leaves ProGuard active, but ProGuard won't change the code. If it doesn't fix the issue. the problem lies elsewhere.