我正在尝试Android Jetpack导航,但出现此错误:
const mongoose = require("mongoose");
const { mongoUrl } = require("../config.js");
const MyModel = require("../models/MyModel");
async function run() {
mongoose.set("useCreateIndex", true);
await mongoose.connect(mongoUrl, { useNewUrlParser: true });
const r = [/* */]; // <-- Something with 500k objects
const total = r.length;
for (let i in r) {
const e = r[i];
e.REF = e.REF.trim();
await MyModel.findOneAndUpdate({ REF: e.REF }, e, { upsert: true, new: true });
if (i % 500 === 0) {
console.log((i / total) * 100 + "%");
}
}
}
run();
Project build.gradle文件具有以下版本:
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]]
应用程序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"
}
}
Google搜索没有产生任何声明了“ android.view.vector”的库。有谁知道需要添加哪个依赖项?在Android jetpack中遇到过类似的问题吗?
谢谢。
更新:
activity_main.xml
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"
}
在layout / nav_header.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>
在gradle.properties文件中:
<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>
答案 0 :(得分:0)
删除此行:
vectorDrawables.useSupportLibrary = true
答案 1 :(得分:0)
为导航视图添加androidx依赖项
implementation 'com.google.android.material.navigation.NavigationView'
答案 2 :(得分:0)
嗨,我认为您需要使用@ layout / nav_header而不是以下行。
app:headerLayout="@drawable/nav_header"