无法使用 RealmAdapter - java.lang.NoClassDefFoundError:解析失败:Landroid/support/v7/widget/TintManager;
Posted
技术标签:
【中文标题】无法使用 RealmAdapter - java.lang.NoClassDefFoundError:解析失败:Landroid/support/v7/widget/TintManager;【英文标题】:Not able to use RealmAdapter - java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/TintManager; 【发布时间】:2016-05-09 16:56:58 【问题描述】:我正在尝试在我的一个项目中使用 Realm Adapter。但是我无法使用它。
每当我将 compile 'io.realm:android-adapters:1.0.1'
添加到 gradle 文件中时。项目编译成功,但应用程序在 tabLayout.setupWithViewPager(viewPager);
上崩溃——我将 viewpager 添加到 tabLayout 的行。
当我评论compile 'io.realm:android-adapters:1.0.1'
时应用程序运行成功
我附上了它崩溃的活动的屏幕截图。它在第 57 行崩溃。我还粘贴了错误的堆栈跟踪
05-09 22:11:48.074 16932-16932/com.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app, PID: 16932
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/TintManager;
at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1185)
at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656)
at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:386)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:361)
at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645)
at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
at com.app.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
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)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.TintManager" on path: DexPathList[[zip file "/data/app/com.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app-1/lib/arm64, /data/app/com.app-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1185)
at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656)
at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:386)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:361)
at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645)
at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
at com.app.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
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)
Suppressed: java.lang.ClassNotFoundException: android.support.v7.widget.TintManager
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
这是来自应用程序的 build.gradle 文件的 sn-p -
dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'
【问题讨论】:
【参考方案1】:所有支持库必须具有相同的版本。 23.1.0 或 23.1.1 或任何其他版本,但您不能使用不同的版本。
尝试对所有库使用23.3.0
。
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'
More reference
【讨论】:
【参考方案2】:io.realm:android-adapters:1.0.1
需要 appcompat-v7
23.3.0 或更高版本。
顺便说一句,我建议为支持版本使用一个变量。 (在所有支持库中应该是相同的。)
def supportVersion = '23.3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile "com.android.support:cardview-v7:$supportVersion"
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'
【讨论】:
以上是关于无法使用 RealmAdapter - java.lang.NoClassDefFoundError:解析失败:Landroid/support/v7/widget/TintManager;的主要内容,如果未能解决你的问题,请参考以下文章
Google App Engine JSP 无法部署:java.lang.RuntimeException:无法获取系统 Java 编译器。请使用 JDK,而不是 JRE
无法使用 Maven 编译简单的 Java 10 / Java 11 项目