- Home /
Android Plugin in Unity - No Return Value
im trying to create an android plugin and import it in unity but i always get 0 as return value from the plugin method and i cant fix this issue.
Here is what i did:
AndroidStudio: -Created a new project -Created a library module (package: com.projectm.myplugin) -Created Public Class "myclass" -Build -> "Make Module 'myplugin'" -copied "classes.jar" file into "Assets/Plugins/Android" in Unity
Full Java Code:
package com.projectm.myplugin;
public class myclass {
public int mymethod(){
return 110;
}
}
And here is my c# script:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextScript : MonoBehaviour
{
public Text Text1;
private AndroidJavaObject JavaTimerClass;
// Start is called before the first frame update
void Start()
{
//Text Text1 = GetComponent<Text>();
JavaTimerClass = new AndroidJavaObject("com.projectm.myplugin.myclass");
Text1.text = JavaTimerClass.Call<int>("mymethod").ToString();
}
// Update is called once per frame
void Update()
{
}
void OnApplicationPause(bool pause)
{
if (pause)
{
}
else
{
}
}
}
TextPlugin.text should display "110" but its always 0. It seems like the name of the package cant be found Hopefully someone can help me. Im new to unity⩓roidstudio and followed many tutorials on youtube but i cant fix this issue.
Im trying to fix this bug since over a week. guys please i need help.
Unity Version: 2019.3.13f1
Your answer
Follow this Question
Related Questions
Android Plugin in Unity - No Return Value 0 Answers
FB Gift Requests not appearing as Push Notification 0 Answers
How do I override an Android Java class in Unity? 1 Answer
Problem in android java plugin 0 Answers
Android: Intent extras not being received when launching an already-open UnityPlayerNativeActivity 0 Answers