Android suspend functions

Hello Community:

 I am creating a library submodule to be used in couple of android apps.

 Currently I am struggling with suspend functions

interface A {
suspend fun testFunction(someParam: List): List
}

after applying proguard I am getting something like:

interface A {
public Object testFunction(someParam:List, arg2:Continuation<List>)
}

how I can avoid this and have a kotlin ready code

Hi @darienalvarez,

Welcome to PG community.

Can you try adding the following keep options?

-keepattributes Signature
-keep class kotlin.coroutines.Continuation

Please let me know if this resolves the issue.

Thanks!
Jack

Hello Community:

I’m in the same situation as @ darienalvarez

I try add @ jack’s advice, but “suspend fun” still become Object and Continuation after proguard.

how I can avoid this and have a kotlin ready code?

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
dependencies
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
classpath("com.android.tools.build:gradle:7.2.2")
classpath("com.guardsquare:proguard-gradle:7.3.0")
plugins
id 'com.android.library'
id 'com.guardsquare.proguard'

If you’re using Kotlin specific features, you might need to keep the Kotlin metadata.

In ProGuard 7.3.+, this is done by using the -keep rule -keep class kotlin.Metadata {*;} and keep the entities on which you want to keep metadata.

In ProGuard <7.3, you need to use the -keepkotlinmetadata rule.

See the manual page for Kotlin for more information: ProGuard Manual: Kotlin | Guardsquare

1 Like