SpaceMadness / lunar-unity-console

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

"Can't init platform" on Android #139

Closed mleenhardt closed 5 years ago

mleenhardt commented 5 years ago

We're seeing the following exception when trying to initialize the plugin on Android. We're building using the built-in gradle build system with Unity 2018.3.0f2, we're using Lunar Console 1.6 (latest on the asset store). We're not seeing any issue on iOS, the console works just fine on this platform.

[Lunar Mobile Console] Can't init platform
java.lang.ClassNotFoundException: spacemadness.com.lunarconsole.console.ConsolePlugin
java.lang.ClassNotFoundException: spacemadness.com.lunarconsole.console.ConsolePlugin
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:400)
    at java.lang.Class.forName(Class.java:326)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.c(Unknown Source)
    at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
    at android.os.MessageQueue.next(MessageQueue.java:392)
    at android.os.Looper.loop(Looper.java:136)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Didn't find class "spacemadness.com.lunarconsole.console.ConsolePlugin" on path: DexPathList[[zip file "/data/app/com.company.project-1/base.apk"],nativeLibraryDirectories=[/data/app/com.company.project-1/lib/arm, /data/app/com.company.project-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 9 more
  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (System.IntPtr clazz, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <00000000000000000000000000000000>:0 
  at LunarConsolePlugin.LunarConsole+PlatformAndroid..ctor (System.String targetName, System.String methodName, System.String version, System.Int32 capacity, System.Int32 trim, System.String gesture, LunarConsolePlugin.LunarConsoleSettings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at LunarConsolePlugin.LunarConsole.CreatePlatform (System.Int32 capacity, System.Int32 trim, LunarConsolePlugin.LunarConsoleSettings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at LunarConsolePlugin.LunarConsole.InitPlatform (System.Int32 capacity, System.Int32 trim, LunarConsolePlugin.LunarConsoleSettings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at LunarConsolePlugin.LunarConsole.EnablePlatform () [0x00000] in <00000000000000000000000000000000>:0 
  at project.Client.Initialization.ClientInitializer+<Initialize>d__4.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 

The APK seems to be containing what it should, I can see many Lunar Console related files in it. The plugin (lunar-console.aar) seems to be properly imported and enabled in Unity.

We're enabling Lunar Console programmatically at runtime (i.e. no prefab exists in any scene) using the following code, this is what is throwing the exception above:

public static void Initialize () {
    var go = new GameObject(nameof(LunarConsole));
    go.SetActive(false);

    var lunarConsole = go.AddComponent<LunarConsole>();
    lunarConsole.m_settings = new LunarConsoleSettings {
        exceptionWarning = new ExceptionWarningSettings { displayMode = ExceptionWarningDisplayMode.All },
        logOverlay = new LogOverlaySettings {
            enabled = true,
            colors = new LogOverlayColors()
        },
        sortActions = false,
        sortVariables = false,
        removeRichTextTags = false,
        emails = new[] { "noreply@company.com" }
    };

    go.SetActive(true);
}
weeeBox commented 5 years ago

Hey @mleenhardt,

I just verified both PRO and FREE builds from the Asset Store: everything works as expected. Please, follow this guide to troubleshoot

mleenhardt commented 5 years ago

I have re-installed the plugin before entering this issue, it didn't seem to cause any files to change compared to before the re-install.

Should lunar-console.aar be anywhere in the built APK? I can see the file being written out to /Temp/gradleOut/libs/lunar-console.aar during the build process.

mleenhardt commented 5 years ago

As far as I can tell, the "Install" menu in the Lunar Console option just creates a prefab in the current scene. Is having the prefab in the first scene at edit time a requirement?

weeeBox commented 5 years ago

No, there's no such requirement. I would need to take a closer look at it. It would be helpful if you can share more integration details or a sample project.

On Wed, Apr 3, 2019, 6:24 PM Mathieu Leenhardt notifications@github.com wrote:

As far as I can tell, the "Install" menu in the Lunar Console option just creates a prefab in the current scene. Is having the prefab in the first scene at edit time a requirement?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SpaceMadness/lunar-unity-console/issues/139#issuecomment-479714684, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwA1G_XX8-aRKG_zhi-H-_yICm3o5_Bks5vdVRlgaJpZM4cbqmy .

mleenhardt commented 5 years ago

It turns out that this was caused by Proguard minification. We previously had EditorUserBuildSettings.androidDebugMinification and EditorUserBuildSettings.androidReleaseMinification set to AndroidMinification.Proguard. Setting them to AndroidMinification.None fixes the issue and causes the console to work fine. I'm assuming that using a custom Proguard template and explicitly specifying that lunar-console.aar shouldn't be stripped out would also do the trick.

weeeBox commented 5 years ago

Thanks for the info. I've created a separate issue to track it.

weeeBox commented 5 years ago

@mleenhardt, here's ProGuard config file (Assets/Plugins/Android/proguard-user.txt)

-keep public class spacemadness.com.lunarconsole.settings.*
-keepclassmembers class spacemadness.com.lunarconsole.settings.* {
   public *;
}
-keep public enum spacemadness.com.lunarconsole.settings.ExceptionWarningSettings$** {
    **[] $VALUES;
    public *;
}
-keep public enum spacemadness.com.lunarconsole.settings.Gesture {
    **[] $VALUES;
    public *;
}
-keep public class spacemadness.com.lunarconsole.console.NativeBridge
-keepclassmembers class spacemadness.com.lunarconsole.console.NativeBridge {
   public *;
}