您好我刚刚将Android Studio更新为3.2 canary 2并且我的项目编译正常,但我有一个运行时异常。
这是崩溃:
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)
以前版本的com.android.tools.build:gradle(3.2.0-alpha02)
一切都很好用这是我的成绩档案:
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
}
和:
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'
})
}
我的职业卫士:
-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>;
}
这是一个插件错误,一个Kotlin错误,还是我错过了什么?我不想回到以前的版本。
答案 0 :(得分:1)
在Kotlin中使用反射时,似乎是gradle插件3.2.0-alpha03
的问题:
java.lang.VerifyError拒绝类 尝试子类的kotlin.reflect.jvm.internal.KClassImpl 错误的阶级 kotlin.reflect.jvm.internal.KDeclarationContainerImpl。
<强>修正:强>
alpha02
3.2 Canary 2
以保持对齐https://developer.android.com/studio/archive.html 答案 1 :(得分:1)
这是gradle版本3.2.0-alpha03
的错误在项目的build.gradle中恢复到3.2.0-alpha02对我来说很有用。
答案 2 :(得分:0)
当你在类路径中使用lazy init属性和kotlin-reflect包时,这似乎是一个错误,因为解决方法将所有lazy init prop转换为非lazy或删除对kotlin-reflect的依赖:((
更新:这似乎是android工具链中的问题,通过比较为kotlin / reflect / jvm / internal / KDeclarationContainerImpl生成的dex代码缺少类型检查https://www.diffchecker.com/E8HcXhOW
答案 3 :(得分:0)
3.2 Canary 2在我的机器上3.2.0-alpha03
之前不能运行任何东西。
让一切工作
Android Studio 3.1 Beta 3 Build#AI-173.4595152,建于2018年2月8日 JRE:1.8.0_152-release-1024-b01 x86_64 JVM:JetBrains s.r.o的OpenJDK 64位服务器VM Mac OS X 10.12.6
with distributionUrl gradle-4.5-all.zip
和gradle 3.2.0-alpha02
答案 4 :(得分:0)
如上所述,这是3.2-alpha 3的错误。最新版本(3.2 Canary 5)似乎修复了它。