Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.2 Canary 2 Kotlin runtime VerifyError: Rejecting class

Hi I've just updated Android Studio to 3.2 canary 2 and my project compile fine but I have a runtime exception.

Here is the crash :

FATAL EXCEPTION: main
Process: fr.myApp, PID: 12658
java.lang.VerifyError: Rejecting class kotlin.reflect.jvm.internal.KClassImpl that attempts to sub-class erroneous class kotlin.reflect.jvm.internal.KDeclarationContainerImpl (declaration of 'kotlin.reflect.jvm.internal.KClassImpl' appears in /data/app/fr.myApp-2/split_lib_dependencies_apk.apk)
    at kotlin.reflect.jvm.internal.KClassCacheKt.getOrCreateKotlinClass(kClassCache.kt:63)
    at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.getOrCreateKotlinClass(ReflectionFactoryImpl.java:45)
    at kotlin.jvm.internal.Reflection.getOrCreateKotlinClass(Reflection.java:61)
    at fr.myApp.reusable.base.modules.NewBaseActivity.<clinit>(NewBaseActivity.kt)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    at android.app.ActivityThread.access$1100(ActivityThread.java:229)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7331)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 Caused by: java.lang.VerifyError: Verifier rejected class kotlin.reflect.jvm.internal.KDeclarationContainerImpl due to bad method java.lang.reflect.Method kotlin.reflect.jvm.internal.KDeclarationContainerImpl.tryGetMethod(java.lang.Class, java.lang.String, java.util.List, java.lang.Class, boolean) (declaration of 'kotlin.reflect.jvm.internal.KDeclarationContainerImpl' appears in /data/app/fr.myApp-2/split_lib_dependencies_apk.apk)
    at kotlin.reflect.jvm.internal.KClassCacheKt.getOrCreateKotlinClass(kClassCache.kt:63) 
    at kotlin.reflect.jvm.internal.ReflectionFactoryImpl.getOrCreateKotlinClass(ReflectionFactoryImpl.java:45) 
    at kotlin.jvm.internal.Reflection.getOrCreateKotlinClass(Reflection.java:61) 
    at fr.myApp.reusable.base.modules.NewBaseActivity.<clinit>(NewBaseActivity.kt) 
    at java.lang.Class.newInstance(Native Method) 
    at android.app.Instrumentation.newActivity(Instrumentation.java:1096) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:7331) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

All was working great with the previous version of com.android.tools.build:gradle (3.2.0-alpha02)

Here is my grades files :

buildscript {
ext.realm_version = '4.3.4'
ext.kotlin_version = '1.2.21'
ext.kotlinx_coroutines_version = '0.22.2'
ext.android_arch_version = '1.0.0-alpha9-1'
ext.android_support_version = '27.0.2'
ext.retrofit_version = '2.3.0'
ext.moshi_version = '1.5.0'
ext.okhttp_version = '3.8.0'
ext.constraint_layout_version = '1.0.2'
ext.junit_version = '4.12'
ext.espresso_version = '2.2.2'
ext.dagger_version = '2.13'
ext.picasso_version = '2.5.2'
ext.timber_version = '4.6.0'
ext.chuck_version = '1.1.0'
ext.crashlitycs_version = '2.9.0'
ext.easyImage_version = '1.3.1'
ext.gradleBuild_version = '3.2.0-alpha03'

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://maven.google.com' }
    maven { url "https://jitpack.io" }
    google()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0-alpha03'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "io.realm:realm-gradle-plugin:$realm_version"
    classpath 'io.fabric.tools:gradle:1.+'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and :

    apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

kotlin {
    experimental {
        coroutines "enable"
    }
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "fr.myApp"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Kotlin :
    //implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation "org.jetbrains.kotlin:kotlin-reflect"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version"

    // Support lib :
    implementation "com.android.support:appcompat-v7:$android_support_version"
    implementation "com.android.support:support-v4:$android_support_version"
    implementation "com.android.support:design:$android_support_version"
    implementation "com.android.support:recyclerview-v7:$android_support_version"
    implementation "com.android.support:cardview-v7:$android_support_version"
    implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"

    // Data binding :
    //kapt "com.android.databinding:compiler:$gradleBuild_version"

    // Android lifecycle :
    implementation "android.arch.lifecycle:extensions:1.1.0"
    kapt "android.arch.lifecycle:compiler:$android_arch_version"

    // Networking: Retrofit + moshi :
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
    implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
    implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"

    // Image downloading and caching :
    implementation "com.squareup.picasso:picasso:$picasso_version"

    // Dependencies injection: Dagger 2
    implementation "com.google.dagger:dagger:$dagger_version"
    implementation "com.google.dagger:dagger-android:$dagger_version"
    implementation "com.google.dagger:dagger-android-support:$dagger_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    kapt "com.google.dagger:dagger-android-processor:$dagger_version"

    // Crypto: FB Conceal + SecurePreferences
    implementation 'com.facebook.conceal:conceal:2.0.1@aar'

    // Logging: Crashlytics + Timber + Chuck
    implementation "com.jakewharton.timber:timber:$timber_version"
    implementation("com.crashlytics.sdk.android:crashlytics:$crashlitycs_version@aar") {
        transitive = true
    }
    debugImplementation "com.readystatesoftware.chuck:library:$chuck_version"
    releaseImplementation "com.readystatesoftware.chuck:library-no-op:$chuck_version"

    // Camera
    implementation "com.github.jkwiecien:EasyImage:$easyImage_version"

    // Permissions
    implementation 'com.github.tajchert:nammu:1.2.0'

    testImplementation "junit:junit:$junit_version"
    androidTestImplementation("com.android.support.test.espresso:espresso-core:$espresso_version", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

my pro guard :

-dontwarn okio.**
-dontwarn javax.annotation.**
-keepclasseswithmembers class * {
    @com.squareup.moshi.* <methods>;
}
-keep @com.squareup.moshi.JsonQualifier interface *
-keepclassmembers class kotlin.Metadata {
    public <methods>;
}
-keepclassmembernames class kotlinx.** {
    volatile <fields>;
}

Is this a plugin bug, a Kotlin bug, or am I missing something? I'd prefer not go back to the previous version.

like image 853
Alexis Schultz Avatar asked Feb 16 '18 14:02

Alexis Schultz


2 Answers

This is a bug with gradle version 3.2.0-alpha03

Reverting to 3.2.0-alpha02 in project's build.gradle did the trick for me.

like image 120
Szymon Wysocki Avatar answered Nov 20 '22 08:11

Szymon Wysocki


Seems to be an issue with gradle plugin 3.2.0-alpha03 when using reflection in Kotlin:

java.lang.VerifyError Rejecting class kotlin.reflect.jvm.internal.KClassImpl that attempts to sub-class erroneous class kotlin.reflect.jvm.internal.KDeclarationContainerImpl.

Fix:

  1. Revert gradle to alpha02 in build.gradle (Project)
  2. Downgrade Android Studio to 3.2 Canary 2 to maintain alignment https://developer.android.com/studio/archive.html
like image 23
charles-allen Avatar answered Nov 20 '22 08:11

charles-allen