Search Unity

Android native function cannot be called when Build System is Gradle

Discussion in 'Android' started by QianXiYa, Jul 17, 2019.

  1. QianXiYa

    QianXiYa

    Joined:
    Nov 1, 2017
    Posts:
    27
    Hi,
    Before this problem occurred, I always packaged in internal mode, but because of project requirements, I need to introduce ARFoudation to realize plane recognition, so Gradle packaging must be used.
    I use Android studio to package the native module into an AAR package, which contains a MainActivity inheriting Unity Player Activity. The package names set on both sides of Android and Unity are exactly the same. The calling method code is as follows:

    jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
    jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
    jo.Call ("PLUMEInit");

    Now packaged run error reporting:
    AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='JudgeSysBlueState' signature='()V' in class Ljava.lang.Object;
    java.lang.NoSuchMethodError: no non-static method with name='JudgeSysBlueState' signature='()V' in class Ljava.lang.Object;

    I thought about using MainActivity without inheriting Unity Player Activity, but I don't know how to implement those inherited OnDestroy functions. Please help me, I really don't know how to solve this problem.