Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find class 'kotlin.jvm.internal.DefaultConstructorMarker'

I am currently working on an Android app which is coded in Kotlin. Everything was fine until yesterday, at some point I started to have this error in the logcat and, when this happens, the content of the app is not displayed. Here's the long description:

11-23 17:08:40.819 10472-10472/ch.XXX.XXX W/dalvikvm: DexOpt: resolve class illegal access: Lch/XXX/XXX/commons/features/CouponsManager; -> Lkotlin/jvm/internal/DefaultConstructorMarker;
11-23 17:08:40.819 10472-10472/ch.XXX.XXX E/dalvikvm: Could not find class 'kotlin.jvm.internal.DefaultConstructorMarker', referenced from method ch.XXX.XXX.commons.features.CouponsManager.<init>
11-23 17:08:40.819 10472-10472/ch.XXX.XXX W/dalvikvm: VFY: unable to resolve check-cast 3145 (Lkotlin/jvm/internal/DefaultConstructorMarker;) in Lch/XXX/XXX/commons/features/CouponsManager;
11-23 17:08:40.819 10472-10472/ch.XXX.XXX W/dalvikvm: DexOpt: resolve class illegal access: Lch/XXX/XXX/commons/features/CouponsManager; -> Lkotlin/jvm/internal/DefaultConstructorMarker;

The referenced class is written in Kotlin and was not modified before the error started to appear.

EDIT

here's the class that causes the issue:

class CouponsManager(private val api: RestApi = RestApi()) {

    fun getAllCoupons(): Observable<CouponDataResponse> {
        return Observable.create { subscriber ->

            val callResponse = api.getCoupons()
            val response = callResponse.execute()

            if (response.isSuccessful) {
                val coupons = response.body()

                subscriber.onNext(coupons)
                subscriber.onCompleted()
            } else {
                subscriber.onError(Throwable(response.message()))
            }

        }
    }

    fun getCoupons(): Observable<List<Coupon>> {
        return getAllCoupons().map {
            it.Coupons.map {
                Coupon(it.TopCouponImageUrl, it.BarcodeUrl, it.TopCouponText, it.BottomCouponText, it.BottomCouponImageUrl)
            }
        }
    }

    fun getLoyaltyCards(): Observable<List<Coupon>> {
        return getAllCoupons().map {
            it.Loyalty.map {
                Coupon(it.TopCouponImageUrl, it.BarcodeUrl, it.TopCouponText, it.BottomCouponText, it.BottomCouponImageUrl)
            }
        }
    }

}
like image 921
bontoJR Avatar asked Nov 24 '16 06:11

bontoJR


1 Answers

So, as @DimaRostopira said, Kotlin doesn't work with Instant Run, so that was already turned off, but apparently, after the update to a new version of Android Studio, it seems that a build has been completed to support Instant Run, so some of the already present built classes where only partially compiled and cached.

I tried to clean the project, but I had to manually wipe the whole build folder to make the project correctly running again.

So the solutions is to rm -Rf build/ in the project folder, open Android Studio and re-built everything from scratch.

like image 118
bontoJR Avatar answered Nov 13 '22 01:11

bontoJR