android - 在哪个库中声明了“android.view.vector”?
问题描述
我正在尝试 Android Jetpack Navigation,但出现此错误:
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"
}
}
应用程序 build.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"
}
谷歌搜索没有产生任何声明“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>
在布局/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
解决方案
嗨,我认为您需要使用 @layout/nav_header 而不是以下行。
app:headerLayout="@drawable/nav_header"
推荐阅读
- mysql - 来自 docker 的 mysql 查询出现错误“查询期间与 MySQL 服务器的连接丢失”
- r - 如何在绘图网格之外使用 geom_text?
- json - DynamoDB JSON 还是标准 JSON?
- r - 如何在不删除行的情况下保持对 data.table 中变量的第一次观察?
- http - <"> 在 RFC 中是什么意思?`#1` 呢?
- javascript - 无法使用 document.querySelector 获取元素
- tortoisesvn - 在 TortoiseSVN 的“所做的更改”中查找文件
- google-cloud-dataflow - 数据流 - 分配自定义时间戳时出错
- javascript - TypeError:无法读取未定义 nuxt 的属性“get”
- python - 我正在制作一个 python 网络应用程序。需要帮助了解如何托管、格式化。呈现它