在Android 4.0中不支持android支持v4库但在5.0中工作?

时间:2016-01-18 09:14:16

标签: android xml drawerlayout

Android 4.0版本不支持抽屉布局,如果android-support-v4.jar文件添加,则会发生多个dex文件错误。

我从上周五开始面对这个问题。请帮我。

XML

 <android.support.v4.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--android:layout_below="@+id/topLay"
     android:layout_above="@+id/menu_lay" -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>

   <ListView
        android:id="@+id/dList"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginBottom="40dp"
        android:choiceMode="singleChoice"
        android:divider="@color/menu_divider_color"
        android:dividerHeight="@dimen/divider_ht"
        android:background="@drawable/side_menu_bg"/>
    <!-- android:layout_width="220dp" -->

</android.support.v4.widget.DrawerLayout>

gradle文件

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':facebook')
compile files('libs/universal-image-loader-1.9.3.jar')
compile('com.twitter.sdk.android:twitter:1.3.1@aar') {
    transitive = true;
}
compile 'com.android.support:multidex:1.0.0'
//for multiple dex library
compile files('libs/PdfViewer.jar')
compile project(':mupdflibrary')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.github.rahatarmanahmed:circularprogressview:2.3.2'
compile project(':gesture-imageview')
compile 'com.android.support:support-v4:23.1.1'
}

错误:

E/AndroidRuntime: FATAL EXCEPTION: 
 main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tatahousing/com.tatahousing.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v4.widget.DrawerLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
     at android.app.ActivityThread.access$600(ActivityThread.java:141)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5103)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:525)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
     at dalvik.system.NativeStart.main(Native Method)
  Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v4.widget.DrawerLayout
     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
     at android.app.Activity.setContentView(Activity.java:1895)
     at com.tatahousing.MainActivity.onCreate(MainActivity.java:227)
     at android.app.Activity.performCreate(Activity.java:5133)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
     at android.app.ActivityThread.access$600(ActivityThread.java:141) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
     at android.os.Handler.dispatchMessage(Handler.java:99) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5103) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
     at dalvik.system.NativeStart.main(Native Method) 
  Caused by: java.lang.reflect.InvocationTargetException
     at java.lang.reflect.Constructor.constructNative(Native Method)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267) 
     at android.app.Activity.setContentView(Activity.java:1895) 
     at com.tatahousing.MainActivity.onCreate(MainActivity.java:227) 
     at android.app.Activity.performCreate(Activity.java:5133) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
     at android.app.ActivityThread.access$600(ActivityThread.java:141) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
     at android.os.Handler.dispatchMessage(Handler.java:99) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5103) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
     at dalvik.system.NativeStart.main(Native Method) 
  Caused by: java.lang.NoClassDefFoundError: android.support.v4.view.AccessibilityDelegateCompatIcs
     at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateIcsImpl.newAccessiblityDelegateDefaultImpl(AccessibilityDelegateCompat.java:122)
     at android.support.v4.view.AccessibilityDelegateCompat.<clinit>(AccessibilityDelegateCompat.java:302)
     at android.support.v4.widget.DrawerLayout.<init>(DrawerLayout.java:175)
     at android.support.v4.widget.DrawerLayout.<init>(DrawerLayout.java:347)
     at java.lang.reflect.Constructor.constructNative(Native Method) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267) 
     at android.app.Activity.setContentView(Activity.java:1895) 
     at com.tatahousing.MainActivity.onCreate(MainActivity.java:227) 
     at android.app.Activity.performCreate(Activity.java:5133) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
     at android.app.ActivityThread.access$600(ActivityThread.java:141) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
     at android.os.Handler.dispatchMessage(Handler.java:99) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5103) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
     at dalvik.system.NativeStart.main(Native Method) 

1 个答案:

答案 0 :(得分:0)

在您的应用程序gradle文件中添加以下依赖项,并删除externa jar文件。

compile 'com.android.support:support-v4:23.1.1'