简体   繁体   中英

(Android Unity plugin) i created a simple plugin, expected 123, got 0

I'm trying to make a plugin for Unity, but not even the simplest class works.

In Android Studio I created a library module, and in it, the following class:

package com.vuforia.android.pluginlib;

import static android.os.Looper.getMainLooper;

public class Multi {
    static public Multi mult=new Multi();
    static public int testes =123;
}

After that I added to the gradle of lib, the following configurations of a Task,to create the aar:

task copyPlugin (type : Copy){
    dependsOn assemble
    from ('build/outputs/aar')
    into ('../../Assets/Plugins/Android')
    include(project.name+'-release.aar')
}

In unity, I created some sprite, and added such script to it:

using UnityEngine;

public class movetest : MonoBehaviour
{
    private AndroidJavaClass javaClass = null;
    void Update()
    {

        javaClass = new AndroidJavaClass("com.vuforia.android.pluginlib.Multi");
        int i = javaClass.GetStatic<int>("testes");
        Debug.Log("->>"+i);
    }

}

and when clicking on run, then what is received "- >>0".

I assume you are running in the editor because you stated "when clicking on run"..

Java plugins will not work in the editor. You would need to deploy to an Android device to test the functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM