Android App仅在Android 6上崩溃 [英] Android App crash only on Android 6

查看:63
本文介绍了Android App仅在Android 6上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个小应用程序,但是仅在Android 6在第一个活动抽屉中由android studio创建的这一行代码上会崩溃:

I have create a small application but this crash only on Android 6 on this line of code create by android studio in first activity drawer:

setContentView(R.layout.activity_home);

错误:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application/com.application.Home}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView

详细错误:

 Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)

此应用程序仅在此设备/ android 6上崩溃,而在android 7和8上则没问题,代码在以下任何方面都是正确的:

This app crash only on this device/android 6, with android 7 and 8 no problem, the code is correct in any way like:

<application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:roundIcon="@drawable/logo"
        android:supportsRtl="true"
        android:hardwareAccelerated="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Home"
            android:keepScreenOn="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">

和xml的相同完美代码:

and same perfect code for xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:id="@+id/main_content"
    android:layout_height="match_parent"
    tools:context=".Home">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_home" />

</android.support.design.widget.CoordinatorLayout>

内部版本:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            useProguard true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true               
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
    implementation 'com.google.zxing:core:3.3.2'
    //implementation 'io.github.tonnyl:whatsnew:+'
    implementation 'com.github.GrenderG:Toasty:1.2.5'
    implementation 'com.shawnlin:number-picker:2.4.6'
    implementation "com.tonyodev.fetch2:fetch2:2.1.0-RC3"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

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


推荐答案

您遇到此问题的原因是,您只有 drawable-v24 中有资源,并且您试图在v23中引用它们( Android M)。将它们移动到 drawable 文件夹或 drawable-v23 (如果较低版本中不需要这些资源)

You are experiencing this issue because you have resources in drawable-v24 only and you are trying to reference them in v23 (Android M). Either move them to drawable folder or drawable-v23 (if these resources are not required in lower version)

这篇关于Android App仅在Android 6上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆