Unity插件在使用Notification Compat Builder时出错

时间:2016-12-24 16:31:09

标签: java android android-studio unity3d gradle

所以,

我为Unity创建了一个Notification插件,它在我使用时工作正常(Notification = New Notification.Builer)

但是我想使用NotificationCompatBuilder访问旧设备,因此它可以在所有api级别使用。

当我使用它并尝试运行它时会给我这个错误

12-24 18:59:31.774: E/AndroidRuntime(10086): FATAL EXCEPTION: main
12-24 18:59:31.774: E/AndroidRuntime(10086): Process: com.blah.blahblah, PID: 10086
12-24 18:59:31.774: E/AndroidRuntime(10086): java.lang.Error: FATAL EXCEPTION [main]
12-24 18:59:31.774: E/AndroidRuntime(10086): Unity version     : 5.4.2f2
12-24 18:59:31.774: E/AndroidRuntime(10086): Device model      : LGE Nexus 5
12-24 18:59:31.774: E/AndroidRuntime(10086): Device fingerprint: google/hammerhead/hammerhead:6.0.1/M4B30X/3237893:user/release-keys
12-24 18:59:31.774: E/AndroidRuntime(10086): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/NotificationCompat$Builder;
12-24 18:59:31.774: E/AndroidRuntime(10086):    at com.blah.soundlibrary.MusicService.showNotification(MusicService.java:383)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at com.blah.soundlibrary.MusicService.onStartCommand(MusicService.java:302)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.app.ActivityThread.-wrap17(ActivityThread.java)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.os.Handler.dispatchMessage(Handler.java:102)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.os.Looper.loop(Looper.java:148)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at android.app.ActivityThread.main(ActivityThread.java:5417)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at java.lang.reflect.Method.invoke(Native Method)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-24 18:59:31.774: E/AndroidRuntime(10086): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.app.NotificationCompat$Builder" on path: DexPathList[[zip file "/data/app/com.blah.blahblah-2/base.apk"],nativeLibraryDirectories=[/data/app/com.blah.blahblah-2/lib/arm, /data/app/com.blah.blahblah-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
12-24 18:59:31.774: E/AndroidRuntime(10086):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-24 18:59:31.774: E/AndroidRuntime(10086):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
12-24 18:59:31.774: E/AndroidRuntime(10086):    ... 11 more
12-24 18:59:31.774: E/AndroidRuntime(10086):    Suppressed: java.lang.ClassNotFoundException: android.support.v4.app.NotificationCompat$Builder
12-24 18:59:31.774: E/AndroidRuntime(10086):        at java.lang.Class.classForName(Native Method)
12-24 18:59:31.774: E/AndroidRuntime(10086):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
12-24 18:59:31.774: E/AndroidRuntime(10086):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
12-24 18:59:31.774: E/AndroidRuntime(10086):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
12-24 18:59:31.774: E/AndroidRuntime(10086):        ... 12 more
12-24 18:59:31.774: E/AndroidRuntime(10086):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

是的,我已经使用

  

import android.support.v4.app.NotificationCompat;

我正在使用Android Studio和Library .aar文件来构建统一插件

试图解决这个问题半天几乎是lol

编辑:添加" com.android.support:support-v4:25.1.0" gradle也没有解决它。

编辑-2:我认为可以通过添加' support-v4-25.1.0'来解决问题。 (我从SDK文件夹获得)到#34;资产/插件/ Android"但它仍然给我同样的错误我认为它仍然没有看到.aar文件:我很困惑

1 个答案:

答案 0 :(得分:0)

更新&回答:好的,所以当我看到这个日志错误时

  

android.support.v4.app.NotificationCompat $生成器

我虽然问题出在 support.v4.25.1.0.aar 文件中但是当我添加 support-compat-25.1.0.aar 错误时走了,现在它的工作。而且不再需要 support.v4.25.1.0.aar ......