繁体   English   中英

由于androidx抽屉布局而导致的错误

[英]Errors due to androidx drawerlayout

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.cn/com.example.cn.MainActivity}:android.view.InflateException:二进制XML文件第2行:二进制XML文件第2行:膨胀类错误android.support.v4.widget.DrawerLayout

<?xml version="1.0" encoding="utf-8"?>  
<androidx.drawerlayout.widget.DrawerLayout  
xmlns:android="http://schemas.android.com/apk/res/android"  
xmlns:app="http://schemas.android.com/apk/res-auto"  
xmlns:tools="http://schemas.android.com/tools"  
android:id="@+id/drawable_layout"  
android:layout_width="match_parent"  
android:layout_height="match_parent"  
android:paddingLeft="10dp"  
android:paddingBottom="5dp"  
tools:context="com.example.cn.MainActivity"  
android:paddingStart="10dp"  
tools:ignore="RtlSymmetry">  

应用

“””

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.cn"
minSdkVersion 16
targetSdkVersion 28
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'])  
//noinspection GradleCompatible  
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'  
implementation 'com.google.android.material:material:1.1.0-alpha04'  
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'  
implementation 'de.hdodenhof:circleimageview:3.0.0'  
implementation 'com.google.firebase:firebase-core:16.0.7'  
implementation 'com.google.firebase:firebase-auth:16.1.0'  
implementation 'com.google.firebase:firebase-messaging:17.4.0'  
apply plugin: 'com.google.gms.google-services'  
implementation 'com.firebaseui:firebase-ui-database:4.3.1'  
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'  
implementation 'com.squareup.picasso:picasso:2.71828'  
implementation 'com.google.firebase:firebase-database:16.1.0'  
implementation 'com.google.firebase:firebase-storage:16.1.0'  
testImplementation 'junit:junit:4.12'  
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'  
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-   
alpha01'  
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'    
}  

“””

检查是否已添加依赖项。

dependencies {
   implementation 'com.android.support:appcompat-v7:28.0.0'
   implementation 'com.android.support:design:28.0.0'
}

然后使用标记android.support.v4.widget.DrawerLayout。

我认为您已经在java类或kotlin类中定义了v4版本的抽屉布局。 那就是为什么它给你错误

错误很明显。 您正在dependencies中使用Android Support Libraries ,但是在layout您尝试使用androidx

例如:

Android支持Libray: com.android.support:appcompat-v7 : com.android.support:appcompat-v7

AndroidX: androidx.appcompat:appcompat:1.0.0

因此,您有两个选项之一,或者继续使用Android Support Libraries ,这意味着您需要将DrawerLayout重命名为<android.support.v4.widget.DrawerLayout或将项目升级到AndroidX

要进行升级,您可以通过Refactor -> Migrate to AndroidX从Android Studio进行升级。

如果您决定使用这种方式,请遵循Android Studio提供的建议,它将zip您的项目,然后进行升级。 这意味着您始终可以在升级AndroidX之前返回项目。

另外,升级后并非所有功能都可以正常运行,并且可能需要手动调整。

或手动: https : //developer.android.com/jetpack/androidx/migrate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM