gpt4 book ai didi

android.support.design.widget.NavigationView 膨胀问题(目标 api 23,最小 api 10)

转载 作者:行者123 更新时间:2023-11-29 14:26:55 25 4
gpt4 key购买 nike

我使用的是 eclipse,之前只使用 android-support-v7-appcompt。以最低 API 10 为目标 API 23。我想开始更新一些 UI,所以我获取了 android-support-design 库并决定从这里开始的 NavigationView (http://www.android4devs.com/2015/06/navigation-view-material-design-support.html)。

起初我在我的主要 Activity android.support.design.widget.NavigationView 膨胀期间遇到错误,因为它找不到资源,因为我的 android.support.design 库不针对 API 23。我修复了那个,现在我在同一个通货膨胀期间仍然处于我的最新错误,看起来它找不到 android.support.design.internal.NavigationMenuView 。

这是在运行 API 19 的模拟器中(我上次尝试时 api 23 英特尔模拟器没有为我加载)。我在所有项目(设计、appcompat、我的基础库和我的 ndk/java 混合代码、构建我的 apk 的顶级项目,这样我就可以根据我的数据拥有不同的 apk)中添加了一堆 pro-guard。

这导致过去两天损失了许多小时,但到目前为止没有任何收获。截至昨天,这两个支持库都是最新的。我仍在使用 eclipse,因为当我几个月前尝试转换到 Android Studio 时它破坏了我的整个目录结构并且不会构建我所有的 ndk 库(有几个)所以我没有时间研究 Android Studio一会儿,我想这对我没有帮助。

我的主要 Activity 开始:

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
try{
setContentView(R.layout.activity_main);
}
catch (Exception e) {
e.printStackTrace();
}
....

这是捕获的堆栈跟踪的打印输出

11-22 15:01:30.394: W/dalvikvm(4312): Unable to resolve superclass of Landroid/support/design/internal/NavigationMenuView; (1893)
11-22 15:01:30.394: W/dalvikvm(4312): Link of class 'Landroid/support/design/internal/NavigationMenuView;' failed
11-22 15:01:30.824: W/System.err(4244): android.view.InflateException: Binary XML file line #28: Error inflating class android.support.design.widget.NavigationView
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.createView(LayoutInflater.java:621)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-22 15:01:30.824: W/System.err(4244): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
11-22 15:01:30.824: W/System.err(4244): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
11-22 15:01:30.824: W/System.err(4244): at com.company.app.MainActivity.onCreate(MainActivity.java:68)
11-22 15:01:30.824: W/System.err(4244): at android.app.Activity.performCreate(Activity.java:5231)
11-22 15:01:30.824: W/System.err(4244): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-22 15:01:30.824: W/System.err(4244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-22 15:01:30.824: W/System.err(4244): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-22 15:01:30.824: W/System.err(4244): at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-22 15:01:30.824: W/System.err(4244): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-22 15:01:30.824: W/System.err(4244): at android.os.Handler.dispatchMessage(Handler.java:102)
11-22 15:01:30.824: W/System.err(4244): at android.os.Looper.loop(Looper.java:136)
11-22 15:01:30.824: W/System.err(4244): at android.app.ActivityThread.main(ActivityThread.java:5017)
11-22 15:01:30.824: W/System.err(4244): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 15:01:30.824: W/System.err(4244): at java.lang.reflect.Method.invoke(Method.java:515)
11-22 15:01:30.824: W/System.err(4244): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-22 15:01:30.824: W/System.err(4244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-22 15:01:30.824: W/System.err(4244): at dalvik.system.NativeStart.main(Native Method)
11-22 15:01:30.824: W/System.err(4244): Caused by: java.lang.reflect.InvocationTargetException
11-22 15:01:30.824: W/System.err(4244): at java.lang.reflect.Constructor.constructNative(Native Method)
11-22 15:01:30.824: W/System.err(4244): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.createView(LayoutInflater.java:595)
11-22 15:01:30.824: W/System.err(4244): ... 22 more
11-22 15:01:30.824: W/System.err(4244): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-22 15:01:30.824: W/System.err(4244): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-22 15:01:30.824: W/System.err(4244): at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:97)
11-22 15:01:30.824: W/System.err(4244): at android.support.design.widget.NavigationView.<init>(NavigationView.java:165)
11-22 15:01:30.824: W/System.err(4244): at android.support.design.widget.NavigationView.<init>(NavigationView.java:94)
11-22 15:01:30.824: W/System.err(4244): ... 25 more
11-22 15:01:30.824: W/System.err(4244): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.NavigationMenuView" on path: DexPathList[[zip file "/data/app/com.company.<app>.nyc-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.app.nyc-2, /vendor/lib, /system/lib]]
11-22 15:01:30.824: W/System.err(4244): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-22 15:01:30.824: W/System.err(4244): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-22 15:01:30.824: W/System.err(4244): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-22 15:01:30.834: W/System.err(4244): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-22 15:01:30.834: W/System.err(4244): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
11-22 15:01:30.834: W/System.err(4244): ... 30 more

res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="divider">@color/divider</item>
<item name="windowNoTitle">true</item>
</style>


<style name="SceneTheme" parent="AppTheme" >
<item name="android:typeface">monospace</item>
</style>

<style name="MenuTheme" parent="AppTheme" >
<item name="android:typeface">monospace</item>
<item name="android:textSize">12sp</item>
</style>

</resources>

资源/值-v21

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primaryDark</item>
<item name="android:statusBarColor">@color/primary</item>

</style>

</resources>

主要 Activity xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.app.MainActivity" >

<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_main"
/>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

</FrameLayout>

</LinearLayout>

<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header_navbar"
app:menu="@menu/action_navbar" />

<fragment
android:id="@+id/location_drawer"
android:name="com.company.app.LocationDrawerFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end" />

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

我在所有项目中使用的 proguard.project.txt 文件

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-dontobfuscate
-dontoptimize
-allowaccessmodification
-repackageclasses ''

-keep class com.company.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }

-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }

-keep class android.support.v13.app.** { *; }
-keep interface android.support.v13.app.** { *; }

-keep class android.support.design.** { *; }
-keep class android.support.design.** { *; }

最佳答案

NavigationMenuView 扩展了 RecyclerView。我将 recyclerview 项目添加到我的工作区中,这为我解决了这个问题。

关于android.support.design.widget.NavigationView 膨胀问题(目标 api 23,最小 api 10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33860084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com