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

本文介绍了解决Android项目中因API版本不一致导致的编译错误的方法。主要原因是build.gradle文件中的API版本与虚拟机选择的API等级不一致,通过调整两者到相同版本并重新构建项目即可解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

build.gradle里面用的api版本 是 28
但是,虚拟机选择的api等级是 27 ,然后项目里用了28的api,所以报错。
虚拟机改用28的api或者将build.gradle里面用的api版本降到27就没错了
修改完成后,点击菜单栏的Build,clear一下再次Build,成功无错运行。

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'   // 有的话,修改此处
}

修改完成后,点击菜单栏的Build,clear一下再次Build,成功无错运行。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值