Using the com.unity3d.player package in Java Source File Plugin

Hello,

I would like to use the UnityPlayer class with methods such as UnitySendMessage in a custom Android plugin.
The plugin itself is a simple java File containing the following line:

import com.unity3D.player;

Additionally I have a custom mainTemplate.gradle file containing the following dependency implementation which actually should make sure that the package is included in the build.

implementation fileTree(dir: 'libs', include: ['*.jar'])

I also tried to add the classes.jar file containing the package manually to the Plugins/Android folder but this only results in the build error that the dependency is already included.

Otherwise I get the error:
error: package com.unity3D does not exist

What is the correct way to use the UnityPlayer api in a custom java source file plugin in Unity?
Is it only possible when creating a .jar and .aar plugin by including the classes.jar in the Android project.
The documentation seems not to give any information concerning this issue.

The utilized Unity version is 2019.1.2f1

Thanks in advance!

d should be lowercase in com.unity3d.player. You should not need anything else, .java file should be picked as plugin and compiled when building, just make sure plugin settings are correct (Android platform selected).

1 Like

Thank you, what a stupid mistake!