问题
After I updated my project to AndroidX
with targetSdkVersion
set to 28, my project crashes on installing it from the store for beta testing.
The following is the error log I receive:
2019-07-08 08:28:33.026 32011-32011/? E/AndroidRuntime: FATAL EXCEPTION: main Process: hu.itq.oakprotection, PID: 32011
java.lang.RuntimeException: Unable to start activity ComponentInfo{hu.itq.oakprotection/hu.itq.oakprotection.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.c(Unknown Source:23)
at androidx.appcompat.app.AppCompatActivity.setContentView(Unknown Source:4)
at hu.itq.oakprotection.MainActivity.onCreate(Unknown Source:6)
at android.app.Activity.performCreate(Activity.java:7372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.NoSuchMethodError: No interface method d()I in class Lorg/xmlpull/v1/XmlPullParser; or its super classes (declaration of 'org.xmlpull.v1.XmlPullParser' appears in /system/framework/core-libart.jar)
at androidx.appcompat.view.SupportMenuInflater.a(Unknown Source:5)
at androidx.appcompat.view.SupportMenuInflater.inflate(Unknown Source:25)
at com.google.android.material.navigation.NavigationView.b(Unknown Source:12)
at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:255)
at com.google.android.material.navigation.NavigationView.<init>(Unknown Source:2)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
The following are my dependencies in build.gradle
file:
android {
compileSdkVersion 28
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
def versionBuild = 4 // ezt kell átírni új verzió kirakásakor
defaultConfig {
applicationId "hu.itq.oakprotection"
minSdkVersion 23
targetSdkVersion 28
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.core:core:1.0.2'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.payumoney.sdkui:plug-n-play:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Test error miatt kellett
implementation 'androidx.annotation:annotation:1.1.0'
//Aszinkron hálózatokhoz
implementation 'com.android.volley:volley:1.1.1'
//Facebook
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
//Osm Droid
implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.github.MKergall:osmbonuspack:6.4'
implementation 'com.github.angads25:filepicker:1.1.1'
//Tile provider igényli
implementation 'mil.nga.geopackage:geopackage-android:3.0.2'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'mil.nga.geopackage:geopackage-core:3.0.2'
implementation 'ar.com.hjg:pngj:2.1.0'
implementation 'mil.nga:tiff:2.0.0'
implementation('mil.nga.geopackage:geopackage-android:3.0.2') {
exclude group: 'com.google.android.gms', module: 'play-services'
exclude group: 'com.google.maps.android', module: 'android-maps-utils'
exclude group: 'com.android.support', module: 'support-v13'
}
//Glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
//Mapsforge rendering and database support, which is LGPL
implementation 'org.mapsforge:mapsforge-map-android:0.8.0'
implementation 'org.mapsforge:mapsforge-map:0.8.0'
implementation 'org.mapsforge:mapsforge-themes:0.8.0'
// ExoPlayer
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
//Youtube
implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v1.7.0'}
activity_main.xml:
<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">
<include
layout="@layout/app_bar_main" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimary"
android:backgroundTint="@color/colorWhite"/>
</androidx.drawerlayout.widget.DrawerLayout>
Why am I receiving an android.view.InflateException
error for NavigationView
?
回答1:
There are multiple reasons why this error can occur. Check the following and make sure they are proper:
- Check your code for
drawable
andcolor
resources used inside thecom.google.android.material.navigation.NavigationView
you've used, probably inactivity_main.xml
, if you're using the default Navigation Drawer template code from Android Studio. - Check that the drawable files are in
res/drawable
folder, not inres/drawable-v21
. - Check if you've used
android:backgroundTint()
orandroid:src
or similar inside yourNavigationView
. Since they don't work below android API Level 21, useapp:backgroundTint
orapp:srcCompat
instead.
回答2:
android.view.InflateException: means there is something wrong in your XML file itself.
Please check all your dimensions, color resources, and other resources you have assigned in the XML tag.
Or post your XML file here.
回答3:
You can check your XML file. Something wrong in your xml like menu, nav header and other. In my Case, wrong in res/menu/menu.xml
来源:https://stackoverflow.com/questions/56931348/error-inflating-class-com-google-android-material-navigation-navigationview-afte