GridLayout兼容性 - ClassNotFoundException:未找到类“android.support.v7.widget.GridLayout”

时间:2013-09-13 13:10:19

标签: android grid-layout android-support-library android-gridlayout

我正在尝试在Android 2.2项目中使用GridLayout,并在我的工作区中安装了gridlayout_v7项目后,将其添加到我的项目Android Dependencies中,为其自定义属性添加自定义xmlns,并将其嵌入到我的xml中布局如此:

<android.support.v7.widget.GridLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    grid:columnCount="2"
    grid:rowCount="3" >

    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/quick_contact" />
</android.support.v7.widget.GridLayout>

我在运行时开始收到以下异常:

java.lang.ClassNotFoundException: Didn't find class 
"android.support.v7.widget.GridLayout" on path: DexPathList[[zip file 
"system/framework/android.test.runner.jar", zip file "data/app/<app package>.apk"], 
nativeLibraryDirectories=[data/app-lib/<app package>, /vendor/lib, /system/lib]]

我已经尝试过清理和重建,删除库并再次添加它但无济于事。 关于可能导致这种情况的任何想法?

1 个答案:

答案 0 :(得分:1)

我看到了这个错误。对我来说,我必须在我的依赖项中特别包含网格布局,如下所示:

dependencies {
   ...
   compile 'com.android.support:gridlayout-v7:18.0.+'
}

在此处详细了解如何添加支持库:https://developer.android.com/tools/support-library/features.html