Я испытываю навигацию по Android Jetpack, и я получил эту ошибку:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigation/com.example.android.navigation.MainActivity}: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class vector
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class vector
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.vector" on path: DexPathList[[zip file "/data/app/com.example.android.navigation-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.navigation-1/lib/x86_64, /system/lib64, /vendor/lib64]]
Файл Project build.gradle имеет следующие версии:
buildscript {
ext {
kotlin_version = '1.3.0'
archLifecycleVersion = '1.1.1'
gradleVersion = '3.3.1'
supportlibVersion = '1.0.0'
navigationVersion = '1.0.0-rc02'
dataBindingCompilerVersion = gradleVersion
}
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
}
}
Сборка приложенияФайл .gradle имеет следующие зависимости:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'
android {
compileSdkVersion 28
dataBinding {
enabled = true
}
defaultConfig {
applicationId 'com.example.android.navigation'
minSdkVersion 21
targetSdkVersion 28
vectorDrawables.useSupportLibrary = true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.appcompat:appcompat:$supportlibVersion"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "com.google.android.material:material:$supportlibVersion"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
}
Поиск в Google не дал никакой библиотеки, в которой объявлен «android.view.vector».Кто-нибудь знает, какую зависимость нужно добавить?Возникла похожая проблема в Android Jetpack?
Спасибо.
Обновление:
activity_main.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/navigation"
app:defaultNavHost="true"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@drawable/nav_header"
app:menu="@menu/navdrawer_menu"/>
</androidx.drawerlayout.widget.DrawerLayout>
</layout>
В layout / nav_header.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navHeader"
android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/navHeaderImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/horizontal_margin"
android:layout_marginTop="8dp"
android:layout_marginEnd="@dimen/horizontal_margin"
android:layout_marginBottom="24dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/nav_header" />
</androidx.constraintlayout.widget.ConstraintLayout>
В файле gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m