Android Studio车载应用运行报错:找不到AsyncLayoutInflater类
解决车载应用运行时的AsyncLayoutInflater类找不到错误
运行车载应用时抛出以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/asynclayoutinflater/view/AsyncLayoutInflater
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.asynclayoutinflater.view.AsyncLayoutInflater" on path: DexPathList[[zip file "/data/app/com.example.mycarapplication-lVN5UU1ZLpkjCRu9JNCF9w==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mycarapplication-lVN5UU1ZLpkjCRu9JNCF9w==/lib/x86_64, /system/lib64]]
现有配置文件
应用级build.gradle
plugins { id 'com.android.application' } android { compileSdk 32 defaultConfig { applicationId "com.example.mycarapplication" minSdk 29 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation 'com.android.car.ui:car-ui-lib:2.3.0' //implementation 'androidx.core:core:1.5.0-alpha04' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' }
项目级build.gradle
plugins { id 'com.android.application' version '7.2.1' apply false id 'com.android.library' version '7.2.1' apply false } task clean(type: Delete) { delete rootProject.buildDir }
gradle.properties
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true android.nonTransitiveRClass=true
解决方法
1. 补充缺失的依赖库
错误核心是项目未引入AsyncLayoutInflater所属的依赖包。直接在应用级build.gradle的dependencies块中添加:
implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0'
2. 同步并清理项目
- 点击Android Studio顶部工具栏的Sync Project with Gradle Files按钮,完成依赖同步。
- 执行Build > Clean Project清理旧构建文件,再重新构建项目。
3. 排查依赖冲突(可选)
如果添加依赖后问题仍存在,检查依赖树:
- 打开View > Tool Windows > Gradle,展开项目的Tasks > android > dependencies,运行该任务查看所有依赖,确认
asynclayoutinflater是否被正确引入。 - 若存在版本冲突,可使用
exclude语句排除冲突版本,或升级相关依赖到兼容版本。
4. 配置多Dex(可选)
如果项目启用了多Dex,需确保该类被包含在主Dex中:
- 在
defaultConfig中添加:multiDexEnabled true - 同步多Dex依赖:
implementation 'androidx.multidex:multidex:2.0.1' - 让自定义Application类继承
MultiDexApplication,或在attachBaseContext方法中调用MultiDex.install(this)。
内容的提问来源于stack exchange,提问作者T B
相关产品推荐
相关产品推荐

