Skip to content

Add methods to java class. #19

@Cabal1996

Description

@Cabal1996

Hi I'm trying to add method to existing example class and call it with existing example blueprint node. But on call this node make my app crash on mobile. Method is empty so I'm doing something wrong on declaration level. This is my java :

package com.Plugins.MobileNativeCode;//Use only this package, do not change it!!!

import android.support.annotation.Keep;
import android.os.Bundle;

@Keep
public class MyJavaObjects {

	//----- Returns a new object of the type - Bundle -------------------
	@Keep
	public static Bundle getBundleJava(){
		return new Bundle();
	}

       //MY NEW FUNCTION WHICH DOES NOT WORK
	@Keep
	public void DoStuffFunction()
	{
		int i = 0;
		i = i + 1;
	}
}

this is my c++ call check section //!!!!!THIS IS MY CALL WHICH MAKES APP CRASH!!!!


void UMobileNativeCodeBlueprint::ExampleMyJavaObject(FString& JavaBundle)
{
#if PLATFORM_ANDROID

  // Creating an empty jobject object, assigning it the standard java Bundle class
  // Bundle: https://developer.android.com/reference/android/os/Bundle

  //In order to populate a jobject with a Java class, you need to return it from your static Java function.

  jobject myJavaObject = AndroidUtils::CallJavaCode<jobject>(
    "com/Plugins/MobileNativeCode/MyJavaObjects",  // package (used by com/Plugins/MobileNativeCode) and the name of your Java class.
    "getBundleJava",                               // Name of your Java function.
    "()Landroid/os/Bundle;",                       // Set your own signature instead of an automatic one (Send an empty one if you need an automatic one).
    false                                          // Determines whether to pass Activity UE4 to Java.
    );

 //!!!!!THIS IS MY CALL WHICH MAKES APP CRASH!!!!
  AndroidUtils::CallJavaCode<void>(
      myJavaObject,
      "DoStuffFunction",
      ""
      );


  // Functions such as putString and putDouble are defined inside Bunde. Let's call them with our parameters:

  AndroidUtils::CallJavaCode<void>(
    myJavaObject,         // the type of jobject from which you want to call a local Java function
    "putFloat",           // Name of Java function.
    "",                   // Set your own signature instead of an automatic one (Send an empty one if you need an automatic one).
    "myKey", 1234.f       // A list of your parameters in the Java function.
    );

  AndroidUtils::CallJavaCode<void>(
    myJavaObject,
    "putString",
    "",
    "myKey2", "myValueForBundle"
    );


  // Let's see what's inside our Bundle
  JavaBundle = AndroidUtils::CallJavaCode<FString>(
    myJavaObject,         // the type of jobject from which you want to call a local Java function
    "toString",           // Name of Java function.
    ""                    // Set your own signature instead of an automatic one (Send an empty one if you need an automatic one).
    );

  // After you have finished working with your jobject, you need to delete it
  AndroidUtils::DeleteJavaObject(myJavaObject);

#endif //Android
}

This is the only code I've changed, commenting call stop crashes
I'm using UE 4.24
I've tried to rebuild project multiple time deleting ALL derivative file from both project and plugin, rename function etc. Please help me figure out this. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions