Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a exoplayer library for Unity and having issues applying documentation #11217

Open
Gurwar opened this issue Jun 20, 2023 · 4 comments
Open
Assignees
Labels

Comments

@Gurwar
Copy link

Gurwar commented Jun 20, 2023

Hello exoplayer community. I am coming from a Unity and c# background and am completely new to Android Studio. I am building a custom exoplayer library and am using available exoplayer resources to do so. Unfortunately they don't apply to building plugins for external use and a lot of the related community discussions are outdated. Here is my code for initializing the player in Java.

public static void initializePlayer(Activity unityPlayer) {
    ExoPlayer player = new ExoPlayer.Builder(unityPlayer).build();
}

Here is the Unity side.

    AndroidJNIHelper.debug = true;
    var playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
    Debug.Log("Got activity");
    var plugin = new AndroidJavaClass("com.bmad.exolib.Exo");
    Debug.Log("Found Plugin");
    plugin.CallStatic("test");
    Debug.Log("Found Test");
    plugin.CallStatic("initializePlayer");
    Debug.Log("Found Function");

Unfortunately I hit an error when trying to use the unityPlayer as the context for building the player. Error Unity AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/media3/exoplayer/ExoPlayer$Builder;

Any guidance would be appreciated.

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jun 20, 2023

Thanks for your report.

I think this is a problem with your build and it looks like the Java classes are not visible or some of them are not. You need to make sure that the ExoPlayer classes are accessible from Unity/native.

I'm not an expert in this matter, but probably someone from the community who has experience with Unity can help.

@Gurwar
Copy link
Author

Gurwar commented Jun 20, 2023

I added a baseProjectTemplate.gradle file to the plugins folder and added this in the dependencies
classpath 'com.android.tools.build:gradle:4.0.1'

I am using Unity 2021.3.16, is there anything else required for Unity to have access to Exoplayer?

@Gurwar
Copy link
Author

Gurwar commented Jun 20, 2023

I made a development build and got more details in the logcat, error is in the image.
image

@Gurwar
Copy link
Author

Gurwar commented Jul 7, 2023

Still need help with the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants