我正在使用eclipse,以前只使用android-support-v7-appcompt罚款。使用min API 10定位API 23.我想开始更新一些UI,所以我抓住了android-support-design库并决定从这里开始使用NavigationView(http://www.android4devs.com/2015/06/navigation-view-material-design-support.html)。
起初我在主要活动android.support.design.widget.NavigationView的膨胀期间遇到错误,因为它找不到资源,因为我的android.support.design库没有针对API 23.我修复了那个,现在我仍处于最新的错误状态,在同样的通货膨胀期间看起来无法找到android.support.design.internal.NavigationMenuView。
这是在运行API 19的模拟器中(api 23 intel模拟器最后没有加载我试过)。我在所有项目(设计,appcompat,我的基础库和我的ndk / java混合代码,顶层项目构建我的apk中添加了一堆保护,所以我可以根据我的数据使用不同的apk。
这导致过去两天失去了许多小时,迄今为止没有任何收获。截至昨天,这两个支持库都是最新的。我仍在使用eclipse,因为几个月前我试图转换为Android Studio它破坏了我的整个目录结构,并且不会构建我的所有ndk库(有一些)因此我没有时间研究Android Studio一段时间,并不是说我会在这里帮助我。
我的主要活动开始:
@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 /值/ 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>
RES /值-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>
主要活动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.** { *; }
答案 0 :(得分:9)
NavigationMenuView扩展了RecyclerView。我将recyclerview项目添加到我的工作区中,这为我解决了这个问题。
答案 1 :(得分:0)
我的min sdk版本高于库。更改了库,我确保其他所有内容都已正确添加到库和订单/导出列表后我就没事了。
答案 2 :(得分:0)
确保在gradle构建文件中对appcompat和设计库使用相同版本。例如
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'