adalpari
adalpari

Reputation: 3121

Proguard can't find referenced class after migration to Kotlin

I'm getting which looks to be a simple ProGuard error saying that a referenced class can not be found. The error happened just after migrate the class from Java to Kotlin.

Warning: com.x.android.ui.ads.offerwall.OfferWallLoader$initIronSrc$1$1$run$1$1: can't find referenced class com.x.android.ui.ads.offerwall.OfferWallLoader$initIronSrc$1$1
Warning: com.x.android.ui.ads.offerwall.OfferWallLoader$initIronSrc$1$1$run$1$1: can't find referenced class com.x.android.ui.ads.offerwall.OfferWallLoader$initIronSrc$1$1

The problem is that I'm trying to keep it in the proguard file, but it looks like it's not having effect..

-keep class com.x.android.ui.ads.offerwall.OfferWallLoader$initIronSrc$* { *;}

I'm not sure to understand the difference when keeping a class or a member after $ in the name. How can I fix it, what am I doing wrong?

Edit: this is the migrated code to Kotlin which is failing (the code is simplified):

private fun initIronSrc(activity: Activity) {
    synchronized(initIronSrcLock) {
        if (isIronSourceInitialised) {
            return
        }

        MyStaticClass.callAsync(object : BackgroundRunnable() {
            override fun run(backgroundServiceAccess: BackgroundServiceAccess) {
                synchronized(initIronSrcLock) {
                    if (isIronSourceInitialised) {
                        return
                    }

                    // Init IronSource
                }
            }
        })
    }
}

Notice is failing to access initIronSrc$1$1$run$1$1

Upvotes: 1

Views: 439

Answers (1)

adalpari
adalpari

Reputation: 3121

After some digging and investigation it turned out like is a tracked issue from Jetbrains: https://youtrack.jetbrains.com/issue/KT-16084

Basically: Proguard can't find enclosing class of let closure inside apply closure So, seems to be an issue with nested classes or nested calls.

In my case, I'm enclosing a static method call inside a synchronized block, so proguard is not able to resolve the call.

The solution is get the call out of that block. In this case the sync can be handled anyway, being sure about the single use of the code and the single colaborator initialisation:

private fun initIronSrc(activity: Activity) {
    synchronized(initIronSrcLock) {
        if (isIronSourceInitialised) {
            return
        }
    }

    MyStaticClass.callAsync(object : BackgroundRunnable() {
        override fun run(backgroundServiceAccess: BackgroundServiceAccess) {
            synchronized(initIronSrcLock) {
                if (isIronSourceInitialised) {
                    return
                }

                // Init IronSource
            }
        }
    })
}

Upvotes: 3

Related Questions