Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the UnityPlayerActivity class inside com.unity3d.player

I'm trying to create an Android plugin for my Unity game. I have watched a lot of tutorials (most of them are outdated based on eclipse) and have read the documentation also. I'm using Unity 2019.3.0f6. I want to extend my main activity in Android Studio project with UnityPlayerActivity

enter image description here

I don't understand what does the ending lines mean "Locate the file, and add classes.jar to the classpath Unity uses to compile the new Activity. Compile your Activity source file and package it into a JAR or AAR package, then copy it into your Project folder"

I understand UnityPlayerActivity does not exist in the classes.jar at PlaybackEngines/AndroidPlayer/Variations/mono or il2cpp/Development or Release/Classes/ and so I can't import com.unity3d.player.UnityPlayerActivity; I can only import UnityPlayer and IUnityPlayerLifecycleEvents. I am also interested to understand what is the UnityPlayer class and IUnityPlayerLifecycleEvents in this context.

enter image description here

But the UnityPlayerActivity.java is available at C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\src\com\unity3d\player

How do I add it in the Unity3d library or classes.jar. Or even import it to extend my mainactivity. I don't understand what am I doing wrong here. I am using Android Studio, although I am new to it.

like image 599
Aditya Patil Avatar asked Sep 08 '26 21:09

Aditya Patil


1 Answers

Don't worry, make android plugins for unity could be a little bit messy at the start, even more if you don't have any experience with Android!

Some tips:

  • Project directory structure should be: Assets/Plugins/Android (it's important, I've been struggling for this stupidity here)
  • Insert classes.jar in AndroidStudio project in app/libs.
  • Insert external dependencies (if you are using it) like "support-v4-24.1.1" into Android/libs

To create plugins on AndroidStudio you need to create a library (this steps is to create it from an activity):

  • On graddle remove ID line
  • On the same file, change .implementation to .library

To recompile the plugin do the follow:

  1. Rebuild AndroidStudio solution

  2. Go to AndroidStudio solution...app\build\outputs\aar get the .aar file

  3. Copy and paste it, change the extension from .aar to .zip or .rar
  4. Open the modified file and extract 2 items:

    • classes.jar (this is another classes.jar, not the same stored in app/libs in your AndroidStudio project)
    • AndroidManifest.xml
  5. Copy those files into Unity project in Assets/Plugins/Android (remember, project directory structure is important!)

You can download the classes.jar file (the first one) from my Utility_Repo or from the path you name it D:\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes\classes.jar.

like image 57
Lotan Avatar answered Sep 10 '26 12:09

Lotan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!