Stack size becomes negative after instruction

帅比萌擦擦* 提交于 2020-01-12 05:25:08

问题


It has been pointed out that the reason I am having this problem is because of proguard 4.9, so I went ahead and updated to proguard-5.2.1. But I am still having the same problem. Has anyone found a solution? I confirmed the new version through

 java -jar /projects/tools/android-sdk-macosx/tools/proguard/lib/proguard.jar

and my proguard-rule.pro is simply

#---- Google Cloud Endpoint section
# Needed by google-api-client to keep generic types and @Key annotations accessed via reflection
-keepclassmembers class * {
  @com.google.api.client.util.Key <fields>;
}
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-dontwarn com.google.api.client.**
-dontwarn com.google.common.**

#---- Twitter
-include ../proguard-com.twitter.sdk.android.twitter.txt
-dontwarn okio.**

#---- Remove Logging

    -assumenosideeffects class android.util.Log {
    
  public static int v(...);
  public static int i(...);
  public static int w(...);
  public static int d(...);
    
  public static int e(...);

    }

#---- support design
-dontwarn android.support.design.**

#---- Google ILicencingService
-keep public class com.google.vending.licensing.ILicensingService
    
-keep public class com.android.vending.licensing.ILicensingService
    
    

The error lines is

Error:java.lang.IllegalArgumentException: Stack size becomes negative after instruction [72] invokestatic #16 in [com/path/android/jobqueue/BaseJob.safeRun(I)Z]

Thanks for any hints.

CORRECTION

Since I am using Android Studio, it sounds like I have to deal with the Proguard plugin. How do I update the plugin? Maybe that might help.


回答1:


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

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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/33595645/stack-size-becomes-negative-after-instruction

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