How to solve java.lang.ClassNotFoundException ?
Hi there,
I tried this tutorial for creating a JAR library for my game. I kept everything simple but I can't find the problem here. Let me explain:
1- I created a JAR library named "MediaPlayerPlugin" with Android Studio, there is a class named "TutorialClass" in it with a simple log.
package com.halluvision.mediaplayerlibrary;
import android.util.Log;
public class TutorialClass {
public void LogNativeAndroidLogcatMessage(){
Log.d("Unity", "Native Logcat Message!");
}
}
2- Put the JAR file in "Assets/Plugins/Android" path in and empty unity project.
3- Created a script and gameObject in my scene:
using UnityEngine;
public class PluginWrapper : MonoBehaviour
{
private AndroidJavaObject javaClass;
void Start()
{
javaClass = new AndroidJavaObject("com.halluvision.mediaplayerlibrary.TutorialClass");
javaClass.Call("LogNativeAndroidLogcatMessage");
}
}
4- Build and run my project in my Poco F1 phone with android 11.
Result: The Logcat shows this error on Start:
2021-07-28 19:17:27.616 31888-31928/com.Halluvision.MediaPlayerTutorial E/Unity: AndroidJavaException: java.lang.ClassNotFoundException: com.halluvision.mediaplayerlibrary.TutorialClass
java.lang.ClassNotFoundException: com.halluvision.mediaplayerlibrary.TutorialClass
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:224)
at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.halluvision.mediaplayerlibrary.TutorialClass" on path: DexPathList[[zip file "/data/app/com.Halluvision.MediaPlayerTutorial-8TdElXhtpVKNJfGodSFsDg==/base.apk"],nativeLibraryDirectories=[/data/app/com.Halluvision.MediaPlayerTutorial-8TdElXhtpVKNJfGodSFsDg==/lib/arm, /data/app/com.Halluvision.MediaPlayerTutorial-8Td
So can you help me to find out why my plugin is not recognized on build?
Comment
I hit the same problem. As suggested at other topics, disabling Minify, or adding option -keep to proguard did not help. Did you find any solutions?