SpaceMadness / lunar-unity-console

High-performance Unity iOS/Android logger built with native platform UI
https://www.assetstore.unity3d.com/en/#!/content/43800
Other
833 stars 112 forks source link

Doesn't work on android with unity 2023.1 #218

Open Tr0sT opened 1 year ago

Tr0sT commented 1 year ago

"failed to verify android.view.view spacemadness.com.lunarconsole.console"

Zoxan commented 1 year ago

Same problem. Android app crashes on launch with error: FATAL EXCEPTION: main Process: com.myapp.name, PID: 18604 java.lang.VerifyError: Verifier rejected class spacemadness.com.lunarconsole.console.ManagedPlatform: android.view.View spacemadness.com.lunarconsole.console.ManagedPlatform.getTouchRecipientView() failed to verify: android.view.View spacemadness.com.lunarconsole.console.ManagedPlatform.getTouchRecipientView(): [0x4] returning 'Reference: com.unity3d.player.UnityPlayer', but expected from declaration 'Reference: android.view.View' (declaration of 'spacemadness.com.lunarconsole.console.ManagedPlatform' appears in base.apk!classes2.dex) at spacemadness.com.lunarconsole.console.NativeBridge$2.execute(NativeBridge.java:89) at spacemadness.com.lunarconsole.concurrent.DispatchTask.run(DispatchTask.java:66) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7050) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Unity 2023.1.3 LunarConsole 1.8.5

orionsdev commented 8 months ago

I have the same issue, my game crashes on start, please help! Crash log: 1701493362342

VladTempest commented 6 months ago

Yep, same problem. Any solution?

romanchikovboris commented 5 months ago

Same problem

dogramacigokhan commented 1 month ago

The issue happens because the native UnityPlayer class that the plugin tries to cast to View no longer extends the FrameLayout, instead it declares it as an internal field to be accessed. As a workaround, I changed the native ManagedPlatform as below to make the getTouchRecipientView work as expected. If you don't want to go through the hassle of building, I'm also sharing the modified lunar-console.aar file for the free version as a drag and drop replacement for Unity 2023+, hope it works.

NOTE: unityPlayer.getFrameLayout() worked nicely for me, but it's just a workaround, and in an empty project for some reason it couldn't receive the touch events, maybe because of the structure of the views were unexpected, but you can give it a try in any case.

lunar-console.zip - Drag & drop the .aar to [PluginPath]\LunarConsole\Editor\Android.

package spacemadness.com.lunarconsole.console;

import android.app.Activity;
import android.view.View;

import com.unity3d.player.UnityPlayer;

import java.lang.reflect.Field;
import java.util.Map;

import spacemadness.com.lunarconsole.debug.Log;

import static spacemadness.com.lunarconsole.debug.Tags.PLUGIN;

public class ManagedPlatform implements Platform {
    private final UnityScriptMessenger scriptMessenger;

    public ManagedPlatform(String target, String method) {
        scriptMessenger = new UnityScriptMessenger(target, method);
    }

    @Override
    public View getTouchRecipientView() {
        Activity activity = UnityPlayer.currentActivity;
        if (activity == null) {
            Log.e(PLUGIN, "UnityPlayer.currentActivity is null");
            return null;
        }

        UnityPlayer unityPlayer = null;

        try {
            Field unityPlayerField = activity.getClass().getDeclaredField("mUnityPlayer");
            unityPlayerField.setAccessible(true);
            unityPlayer = (UnityPlayer) unityPlayerField.get(activity);
        } catch (Exception e) {
            Log.e(PLUGIN, "Error while getting UnityPlayer instance: %s", e);
        }

        if (unityPlayer == null) {
            Log.e(PLUGIN, "UnityPlayer instance is null");
            return null;
        }

        return unityPlayer.getFrameLayout();
    }

    @Override
    public void sendUnityScriptMessage(String name, Map<String, Object> data) {
        try {
            scriptMessenger.sendMessage(name, data);
        } catch (Exception e) {
            Log.e(PLUGIN, "Error while sending Unity script message: name=%s param=%s", name, data);
        }
    }
}