报错:java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListe

The api version used in build.gradle is 28.
However, the api level selected by the virtual machine is 27, and then the api 28 is used in the project, so an error is reported.
It's OK to switch the virtual machine to API 28 or lower the API version used in build.gradle to 27.
After the modification is completed, click on the menu bar Build, clear and Build again, and it will run successfully without errors.

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27   // 修改此处
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.poppy"
        minSdkVersion 16
        //noinspection OldTargetApi
        targetSdkVersion 27    // 修改此处
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'   // 修改此处
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "org.jetbrains.anko:anko:0.10.8"
    implementation 'com.android.support:support-vector-drawable:27.1.1'    // 有的话,修改此处
    implementation 'com.android.support:mediarouter-v7:27.1.1'   // 有的话,修改此处
    implementation 'com.android.support:support-v4:27.1.1'   // 有的话,修改此处
}

After the modification is completed, click on the menu bar Build, clear and Build again, and it will run successfully without errors.

おすすめ

転載: blog.csdn.net/lojloj/article/details/99343494