Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't init platform" on Android #139

Closed
mleenhardt opened this issue Apr 4, 2019 · 8 comments
Closed

"Can't init platform" on Android #139

mleenhardt opened this issue Apr 4, 2019 · 8 comments

Comments

@mleenhardt
Copy link

mleenhardt commented Apr 4, 2019

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
Copy link
Member

weeeBox commented Apr 4, 2019

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
Copy link
Author

mleenhardt commented Apr 4, 2019

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
Copy link
Author

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
Copy link
Member

weeeBox commented Apr 4, 2019 via email

@mleenhardt
Copy link
Author

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
Copy link
Member

weeeBox commented Apr 5, 2019

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

@weeeBox
Copy link
Member

weeeBox commented Apr 5, 2019

@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 *;
}

@weeeBox weeeBox closed this as completed Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@weeeBox @mleenhardt and others