Kotlin optimization "Unexpected error while computing stack sizes"
Java class file shrinker, optimizer, obfuscator, and preverifier
Brought to you by:
guardsquare
Cannot build release version, because of this:
Unexpected error while computing stack sizes:
Class = [com/olekdia/androidcommon/extensions/PowerExtensionsKt]
Method = [acquireCpu(Landroid/content/Context;Ljava/lang/String;J)V]
Exception = [java.lang.IllegalArgumentException] (Stack size becomes negative after instruction [148] pop in [com/olekdia/androidcommon/extensions/PowerExtensionsKt.acquireCpu(Landroid/content/Context;Ljava/lang/String;J)V])
Here is the PowerExtensionsKt:
package com.olekdia.androidcommon.extensions
import android.annotation.SuppressLint
import android.content.Context
import android.os.PowerManager
import androidx.collection.SimpleArrayMap
private const val INFINITE_TIMEOUT = -1L
private val wakeLockMap = SimpleArrayMap<String, PowerManager.WakeLock>(0)
@SuppressLint("WakelockTimeout")
fun Context.acquireCpu(
tag: String,
timeout: Long = INFINITE_TIMEOUT
) {
synchronized(wakeLockMap) {
wakeLockMap.get(tag)
?.apply {
if (!isHeld) {
if (timeout == INFINITE_TIMEOUT) acquire() else acquire(timeout)
}
}
?: run {
this.powerManager
?.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE,
tag
)
?.apply {
if (timeout == INFINITE_TIMEOUT) acquire() else acquire(timeout)
wakeLockMap.put(tag, this)
}
}
}
}