Stack size becomes negative after instruction

这一生的挚爱 提交于 2019-12-03 08:13:29
ARRR

Add this line to your proguard-rules.pro file:

-keep interface com.birbit.android.jobqueue.** { *; }

The problem persists for me when using ProGuard version 6.0.1 or 6.0.3. That's why I tried to figure out, what causes the problem.

In my case, the function leading to the error during ProGuard optimization was this (Kotlin or Java should be irrelevant):

private fun logInfo(action: String) {
    val wifiState = mWifiManager.wifiState

    val stateString = when (wifiState) {
        WifiManager.WIFI_STATE_ENABLED -> "enabled"
        WifiManager.WIFI_STATE_DISABLED -> "disabled"
        WifiManager.WIFI_STATE_DISABLING -> "disabling"
        WifiManager.WIFI_STATE_ENABLING -> "enabling"
        WifiManager.WIFI_STATE_UNKNOWN -> "unknown"
        else -> "default"
    }

    val logString = wifiInfo?.run {
        "$action, $stateString, ssid: $ssid, bssid: $bssid, rssi: $rssi, linkSpeed: $linkSpeed"
    } ?: "$action, $stateString"
    MLog.d(LOG_TAG, MLog.LogCategory.Network, logString)
}

The ProGuard Rules included the following statement:

-assumenosideeffects class some.package.MLog {
*** d(...);
*** i(...);
*** w(...);
}

MLog.kt is a custom logging class, its content is irrelevant.

The problem seems to be that ProGuard strips away MLog.d and therefore all the remaining code inside the function is no longer required, up to the point that even the parameter action is no longer needed. My guess is that ProGuard tries to remove the parameter or even the function logInfo altogether. That's what seems to be causing the crash.

If I add this useless bit to the end of the function, the crash doesn't occur:

if (logString == "test") {
    Thread.sleep(1)
}

The reason probably being that now the function parameter is not completely useless (at least not to the compiler), even after (or during) optimization.

As an option, you can change the build.gradle from

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'

to

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'

to turn off optimizations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!