Stack size becomes negative after instruction
Asked Answered
C

3

7

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.

Corby answered 8/11, 2015 at 15:33 Comment(1)
I just hit this as well - on version 5.2.1...Frowsty
M
2

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.

Millner answered 11/2, 2019 at 18:20 Comment(0)
E
0

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

-keep interface com.birbit.android.jobqueue.** { *; }
Exhalation answered 9/1, 2018 at 10:6 Comment(0)
A
0

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.

Alvinaalvine answered 5/10, 2018 at 7:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.