Search Unity

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

Discussion in 'Android' started by DHein, Nov 26, 2019.

  1. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    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:
    Code (CSharp):
    1. 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.
    Code (CSharp):
    1. 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!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    `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).
     
    DHein likes this.
  3. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Thank you, what a stupid mistake!