DrawerLayout在更新到Android 6.0.1后停止正常工作

时间:2015-12-16 14:18:40

标签: android android-6.0-marshmallow

几个小时前我已将我的Android设备版本更新为6.0.1,从那时起我的应用程序崩溃了,因为我离开了持有DrawerLayout的活动,出现此错误:

class Foo {
    var words = Set<String>()

    func add(word:String) {
        if words.contains(word) {
            showMessageToUser()
        } else {
            words.insert(word)
        }
    }

    func showMessageToUser() {
        // ....
    }
}

在以前的所有版本(6.0及更早版本)中,一切似乎都运行良好。

我也检查了这些线程但似乎没有解决问题:

DrawerLayout must be measured with MeasureSpec.EXACTLY error

https://stackoverflow.com/a/30308779/2274300

Navigation Drawer rendering error in ADT Layout Editor

Gradle文件:

12-16 16:08:04.122 9331-9331/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.my.app, PID: 9331
java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:831)
at android.view.View.measure(View.java:18794)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18794)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

DrawerLayout视图是最顶级的,它没有父级:

activity_home.xml

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
    applicationId "com.my.app"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 31
    versionName "1.0"

    }
    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }

    sourceSets {
    main {
        jniLibs.srcDir 'jniLibs'
    }
    }

    packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.android.support:design:22.2.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.squareup.picasso:picasso:2.5.2'
    ...

}

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }


}

1 个答案:

答案 0 :(得分:3)

好的,我发现了问题。

前一段时间我试图删除工具栏导航图标左侧不必要的填充: Android API 21 Toolbar Padding

这就是导致崩溃的原因,我删除了DrawerLayout并仅保留了工具栏视图,现在它正在工作!