简体   繁体   中英

Unity Plugin Gives Error When Using Notification Compat Builder

So,

I created a Notification plugin for Unity it works fine when i use (Notification = New Notification.Builer)

But i want to use NotificationCompatBuilder for access older devices so it can be used in all api levels.

And when i use it and try to run it gives me this error

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

And yes I already use

import android.support.v4.app.NotificationCompat;

I am using Android Studio and Library .aar files to build plugins in unity

Trying to solve this for half a day almost lol

Edit: And adding "com.android.support:support-v4:25.1.0" to gradle didn't solve it either.

Edit-2: I thought the problem can be suppressed by adding the 'support-v4-25.1.0' (which i get from SDK folder) to "Assets/Plugins/Android" but it still gives me the same error i think it still doesn't see the .aar file :S im so confused

Update & Answer : Okay so when i see this log error

android.support.v4.app.NotificationCompat$Builder

I though the problem was with the support.v4.25.1.0.aar file but when i add the support-compat-25.1.0.aar Error is gone and now its working. And no need for support.v4.25.1.0.aar anymore...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM