Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Android Plugin Template

Setup

  1. Rename app/androidplugin directory to the name of your choosing.

  2. Update settings.gradle with the new path (keep the custom path separators :) and display name.

    include ':app:androidplugin'
    rootProject.name = "Unity Android Plugin"
    
  3. Update package name in app/androidplugin/src/main/AndroidManifest.xml and app/androidplugin/src/main/java/com/unity/androidplugin/AndroidPlugin.java.

  4. Build with make build.

Usage in Unity

  1. Create a new folder in Unity's assets panel Plugins/Android.

  2. Import the generated .aar file from dist/ into Plugins/Android.

  3. Create an assembly definition in Plugins/Android, and select only Android and Editor under Platforms.

  4. Create a script in Plugins/Android for accessing the plugin:

    using UnityEngine;
    
    public static class AndroidPlugin
    {
    
        private static AndroidJavaObject _androidPlugin;
    
        private static AndroidJavaObject androidPlugin
        {
            get
            {
                if (_androidPlugin != null)
                {
                    return _androidPlugin;
                }
    
                var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    
                var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    
                _androidPlugin =
                    new AndroidJavaObject("com.unity.androidplugin.AndroidPlugin", currentActivity);
    
                return _androidPlugin;
            }
        }
    
        public static void Toast(string message)
        {
            androidPlugin.Call("ToastMakeText", message);
        }
    
    }
  5. Then call the plugin via AndroidPlugin.Toast("Hello, world!");

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages