Android应用SDK32编译报错:无法解析插值器父类
Android编译错误:无法解析Interpolator父类NativeInterpolator(适配SDK32)
编译错误信息
> Task :app:compileDebugKotlin FAILED e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class android.view.animation.LinearInterpolator, unresolved supertypes: android.graphics.animation.NativeInterpolator class android.view.animation.AccelerateDecelerateInterpolator, unresolved supertypes: android.graphics.animation.NativeInterpolator Adding -Xextended-compiler-checks argument might provide additional information.
项目配置文件
build.gradle (:app)
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-kapt' id 'com.google.dagger.hilt.android' id "jacoco" } jacoco { toolVersion("0.8.11") } apply from: "$project.rootDir/jacoco.gradle" // 从ChangeLog.md获取版本名称 def getVersionName() { File file = file('../ChangeLog.md') return file.readLines().get(0) } // 从ChangeLog.md获取版本号 def getVersionCode() { File file = file('../ChangeLog.md') return file.readLines().get(1) } def versionNameInQuotes = getVersionName() def versionCodeNumber = getVersionCode() as Integer android { namespace 'com.example.testapp' compileSdk 32 defaultConfig { applicationId "com.example.testapp" minSdk 31 targetSdk 32 versionCode versionCodeNumber versionName "$versionNameInQuotes" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" archivesBaseName = "TestApp" } buildFeatures { buildConfig true } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } buildFeatures { viewBinding true } dataBinding { enabled = true } kotlinOptions { jvmTarget = '11' // allWarningsAsErrors = true } packagingOptions { resources { excludes += ['META-INF/INDEX.LIST', 'META-INF/io.netty.versions.properties'] } } testOptions { unitTests.returnDefaultValues = true unitTests.includeAndroidResources = true } } dependencies { implementation fileTree(include: ['*.aar'], dir: 'libs') implementation project(path: ':testservice') implementation Dependencies.core_ktx implementation Dependencies.appcompat implementation Dependencies.material implementation Dependencies.constraintlayout implementation Dependencies.livedata_ktx implementation Dependencies.view_model_ktx testImplementation Dependencies.test_junit androidTestImplementation Dependencies.ext_junit androidTestImplementation Dependencies.espresso_core // Hilt implementation(Dependencies.hilt_android) kapt(Dependencies.hilt_compiler) // Gson converter implementation(Dependencies.gson_retrofit_converter) // Mockito testImplementation(Dependencies.mockito_core) testImplementation(Dependencies.mockito_kotlin) androidTestImplementation(Dependencies.mockito_core) androidTestImplementation(Dependencies.mockito_kotlin) androidTestImplementation Dependencies.mockito_android // 核心测试库 testImplementation Dependencies.core_testing // Hilt测试依赖 androidTestImplementation Dependencies.hilt_android_testing kaptAndroidTest Dependencies.hilt_compiler // Gson implementation Dependencies.gson // 反射 testImplementation Dependencies.kotlin_reflect // 协程测试 testImplementation Dependencies.coroutines_test // DataStore implementation Dependencies.datastore_preferences implementation(Dependencies.coroutines_android) // UI测试 androidTestImplementation(Dependencies.test_runner) androidTestImplementation(Dependencies.test_rules) androidTestImplementation(Dependencies.ui_automator) implementation(Dependencies.espresso_contrib) }
build.gradle (:testservice)
plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' id 'kotlin-kapt' id 'com.google.dagger.hilt.android' id "jacoco" } jacoco { toolVersion("0.8.11") } apply from:"$project.rootDir/jacoco.gradle" android { namespace 'com.example.testservice' compileSdk 32 defaultConfig { minSdk 31 targetSdk 32 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } buildFeatures { buildConfig true } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } dataBinding { enabled = true } kotlinOptions { jvmTarget = '11' } testOptions { unitTests.returnDefaultValues = true unitTests.includeAndroidResources = true } } dependencies { api fileTree(include: ['*.jar'], dir: 'libs') api project(":telematicslib") implementation Dependencies.core_ktx implementation Dependencies.appcompat implementation Dependencies.material // HiveMQ implementation(Dependencies.mqtt_client) // Retrofit implementation(Dependencies.retrofit) // Gson converter implementation(Dependencies.gson_retrofit_converter) implementation(Dependencies.okHttpLoggingInterceptor) implementation files('libs\\extension-V1.0-java.jar') testApi Dependencies.test_junit androidTestApi Dependencies.ext_junit androidTestApi Dependencies.espresso_core // DataStore implementation Dependencies.datastore_preferences implementation(Dependencies.coroutines_android) // Hilt implementation(Dependencies.hilt_android) kapt(Dependencies.hilt_compiler) // Mockito testApi (Dependencies.mockito_core) testApi (Dependencies.mockito_kotlin) // 核心测试库 testApi Dependencies.core_testing // Hilt测试依赖 testApi Dependencies.hilt_android_testing kaptAndroidTest Dependencies.hilt_compiler // 反射 testApi Dependencies.kotlin_reflect // 协程测试 testApi Dependencies.coroutines_test }
已尝试的解决步骤
- Android Studio -> File -> Invalidate cache/restart
- 删除应用的build文件夹
- Build -> Clean Project,Build -> Rebuild Project
- 重启笔记本电脑和Android Studio
- 将compileSdk和targetSdk改为33时应用可正常运行,但需适配SDK32,寻求解决方案
解决方案
降级Android Gradle Plugin(AGP)版本
若使用AGP 7.4+版本,可能会默认启用新编译逻辑,导致SDK32下引用隐藏的NativeInterpolator。可降级至AGP 7.3.x(如7.3.1),同时确保Gradle版本匹配(AGP7.3.x对应Gradle7.5)。添加Kotlin编译参数
在模块的build.gradle的kotlinOptions中添加参数,跳过元数据版本检查:kotlinOptions { jvmTarget = '11' freeCompilerArgs += ['-Xskip-metadata-version-check'] }对齐依赖库版本
确保所有AndroidX依赖(如appcompat、material)版本与compileSdk32兼容,例如使用appcompat 1.5.x系列,而非1.6.x(对应SDK33+)。建议在根目录build.gradle中统一管理依赖版本,避免版本冲突。排查第三方依赖
检查自定义aar/jar包(如extension-V1.0-java.jar)或第三方库是否引入SDK33的API,如有则替换为适配SDK32的版本,或通过exclude语句移除冲突依赖。确保SDK Platform 32完整
通过SDK Manager检查并安装完整的SDK Platform 32(包括Sources和System Images),避免因SDK文件缺失导致类解析错误。
内容的提问来源于stack exchange,提问作者jesto paul
相关产品推荐
相关产品推荐

