Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question ERROR java.lang.NoSuchFieldError: no type "" found and so no field "currentActivity"

Discussion in 'Android' started by Sangemdoko, Aug 12, 2023.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    218
    Hi,

    I am making an app that needs to communicate with an android aar.
    It used to work well a few weeks ago. Since then I've been working on the Unity UI and didn't test the android communication in awhile.

    Now I'm getting an error that I simply don't understand:
    Code (CSharp):
    1. 2023/08/12 02:04:24.141 3621 3686 Error Unity AndroidJavaException: java.lang.NoSuchFieldError: no type "" found and so no field "currentActivity" could be found in class "Lcom/unity3d/player/UnityPlayer;" or its superclasses
    2. 2023/08/12 02:04:24.141 3621 3686 Error Unity java.lang.NoSuchFieldError: no type "" found and so no field "currentActivity" could be found in class "Lcom/unity3d/player/UnityPlayer;" or its superclasses
    3. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    4. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender(Unknown Source:0)
    5. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at com.unity3d.player.UnityPlayer$C$a.handleMessage(Unknown Source:122)
    6. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at android.os.Handler.dispatchMessage(Handler.java:103)
    7. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at android.os.Looper.loop(Looper.java:214)
    8. 2023/08/12 02:04:24.141 3621 3686 Error Unity     at com.unity3d.player.UnityPlayer$C.run(Unknown Source:24)
    9. 2023/08/12 02:04:24.141 3621 3686 Error Unity   at UnityEngine.AndroidJNISafe.CheckException () [0x0008d] in /home/bokken/build/output/unity/unity/Modules/AndroidJNI/AndroidJNISafe.cs:24
    10. 2023/08/12 02:04:24.141 3621 3686 Error Unity   at UnityEngine.AndroidJNISafe.GetStaticFieldID (System.IntPtr clazz, System.String name, System.String sig) [0x0000e] in /home/bokken/build/output/unity/unity/Modules/An
    11.  
    It happens anytime I try to do anything related to Unity/Android.
    Even when I call functions on Permissions.
    For example
    Code (CSharp):
    1. AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    or
    Code (CSharp):
    1. Permission.HasUserAuthorizedPermission(PERMISSION_BLUETOOTH)
    causes this error to popup



    This is my manifest file:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.unity3d.player"
    5.     xmlns:tools="http://schemas.android.com/tools">
    6.     <application>
    7.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    8.                   android:theme="@style/UnityThemeSelector"
    9.                   android:exported="true">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.             <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    15.         </activity>
    16.     </application>
    17. </manifest>
    Here is my publishing settings and Android build options:
    upload_2023-8-12_11-14-16.png

    I'm at a complete loss because I haven't changed anything related the Unity/Android stuff and it used to work fine (I double checked git for any revisions on the manifest file and nothing changed). It's as if the Unity activity didn't exist.

    Any help would be super appriciated.
     
  2. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    218
    This was an absolute nigthmare to debug. Absolutely nothing to go on. But I finally figured it out.

    DO NOT assign a field that derives from a java class in it's definition within a monobehviour. This did not give me any log, warning or error to indicate I shouldn't do this.
    Don't do this:
    Code (CSharp):
    1. private AndroidThermalPrinter.UnityAndroidGetConnectionStatusCallback m_UnityAndroidGetConnectionStatusCallback = new AndroidThermalPrinter.UnityAndroidGetConnectionStatusCallback();
    Do this instead:
    Code (CSharp):
    1. private AndroidThermalPrinter.UnityAndroidGetConnectionStatusCallback m_UnityAndroidGetConnectionStatusCallback;
    2.  
    3. public void Initialize(){
    4. m_UnityAndroidGetConnectionStatusCallback = new AndroidThermalPrinter.UnityAndroidGetConnectionStatusCallback();
    5. }
    6.  
    To figure that out I first made a new scene with a simple toast that executed in awake.

    Then I added that code to my original scene. And I started removing stuff from my scene until that toast didn't throw the error anymore.

    That narrowed it down to the monobehaviours that had those declarations.


    I hope that this will help whoever gets that error in the future to avoid wasting an entire weekend trying to figure it out...
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    It looks to be threading related. You are probably accessing Java from other thread, so you have to attach that thread to Java first.
     
  4. nawin_gamedev

    nawin_gamedev

    Joined:
    Sep 11, 2023
    Posts:
    4
    Could you please explain how to do??
     
  5. nawin_gamedev

    nawin_gamedev

    Joined:
    Sep 11, 2023
    Posts:
    4
    I can't get you,pls elaborate this bcoz I am also facing the same issue
     
  6. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    218
    @nawin_gamedev
    Most likely this error is something that can happen in different ways. The source of your issue might not be the same as you.

    I recommend you do what I did. Duplicate your scene. And then strip it down bit by bit until the error stops happening.
    That'll give you an idea of where the source of the error is.
    Add the problematic object back in the scene so that the error comes back.
    Then manually check the scripts you are using. And comment out stuff related to java until the error stops again.

    That should tell you exactly what line is the problem.
    And then find a way to replace that line with something else

    I know this is not ideal... but it's the only way I found to identify the issue I had.
     
  7. maxbet855bola

    maxbet855bola

    Joined:
    Oct 16, 2023
    Posts:
    1