yasirkula / UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
104 stars 32 forks source link

Error starting unity: GL_INVALID_ENUM : glTexImage2D: <- error from previous GL command #39

Closed juan9506 closed 5 years ago

juan9506 commented 5 years ago

Hi, I followed the steps for a v1 ionic app, and every time I click the button to open the unity part, the screen became black for 1 second and then goes back to the ionic view. After starting the app I get the following erros:

5.820 24867-24938/io.ionic.starter E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-02 07:48:45.920 24867-24938/io.ionic.starter E/chromium: [ERROR:gl_surface_egl.cc(335)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
10-02 07:48:46.390 24867-24938/io.ionic.starter E/chromium: [ERROR:gl_surface_egl.cc(335)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
10-02 07:48:47.690 24867-24937/io.ionic.starter E/chromium: [ERROR:budget_service.cc(145)] Unable to connect to the Mojo BudgetService.
10-02 07:48:47.930 24867-24938/io.ionic.starter E/chromium: [ERROR:texture_manager.cc(3410)] [.RenderWorker-0x5579f8bfc0]GL ERROR :GL_INVALID_ENUM : glTexImage2D: <- error from previous GL command

and when I click the button to launch unity, I get the following erros:

10-02 07:50:01.390 24867-24938/io.ionic.starter E/chromium: [ERROR:texture_manager.cc(3410)] [.RenderWorker-0x5579f8bfc0]GL ERROR :GL_INVALID_ENUM : glTexImage2D: <- error from previous GL command
10-02 07:50:01.450 24867-24938/io.ionic.starter E/chromium: [ERROR:gles2_cmd_decoder.cc(8216)] [.RenderWorker-0x5579f8bfc0.GpuRasterization]GL ERROR :GL_INVALID_ENUM : glFramebufferTexture2D: <- error from previous GL command

I thought it was due to my unity export opengl, but I tried everything (Opengl2, Opengl3, Autographics Enabled) and I still getting the same error and don't see the unity app.

yasirkula commented 5 years ago

What is your Unity version? Does the integration work for a simple scene with nothing but a cube in it?

juan9506 commented 5 years ago

Unity Version: 2018.2.10f1 Yes, the integration works perfect for a simple scene with just a text. but when I change the project to use the vuforia exported project, first, I get the following error: Unable to resolve dependency for ':@debug/compileClasspath': Could not resolve project :UnityProject. so I have to change implementation(':UnityProject') for implementation project(path: ':UnityProject', configuration: 'default') in order to make it work. When I first run it in my phone, I get:

10-03 10:58:39.100 4252-4285/io.ionic.starter E/cr_VariationsUtils: Failed reading seed file "/data/data/io.ionic.starter/app_webview/variations_seed_new": /data/data/io.ionic.starter/app_webview/variations_seed_new: open failed: ENOENT (No such file or directory)
10-03 10:58:39.620 4252-4312/io.ionic.starter E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-03 10:58:39.630 4252-4312/io.ionic.starter E/chromium: [ERROR:gl_surface_egl.cc(335)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
10-03 10:58:39.790 4252-4312/io.ionic.starter E/chromium: [ERROR:gl_surface_egl.cc(335)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
10-03 10:58:40.780 4252-4311/io.ionic.starter E/chromium: [ERROR:budget_service.cc(145)] Unable to connect to the Mojo BudgetService.
10-03 10:58:40.990 4252-4312/io.ionic.starter E/chromium: [ERROR:texture_manager.cc(3410)] [.RenderWorker-0x5579f3ee00]GL ERROR :GL_INVALID_ENUM : glTexImage2D: <- error from previous GL command

but everything works correctly until I click the button to open unity:

[ERROR:gles2_cmd_decoder.cc(2653)] [.RenderCompositor-0x5579f67bb0]GL ERROR :GL_INVALID_ENUM : BackFramebuffer::Destroy: <- error from previous GL command
10-03 10:56:20.500 2608-2608/io.ionic.starter:unityselfprocess E/Unity: Unable to find main
10-03 10:56:20.600 2608-2608/io.ionic.starter:unityselfprocess E/art: No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() (tried Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator and Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator__)
10-03 10:56:20.610 2608-2608/io.ionic.starter:unityselfprocess E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.ionic.starter:unityselfprocess, PID: 2608
    java.lang.Error: FATAL EXCEPTION [main]
    Unity version     : 2018.2.10f1
    Device model      : HUAWEI ALE-L23
    Device fingerprint: Huawei/ALE-L23/hwALE-H:5.0.1/HuaweiALE-L23/COLC112B130:user/release-keys

    Caused by: java.lang.UnsatisfiedLinkError: No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() (tried Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator and Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator__)
        at com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator(Native Method)
        at com.unity3d.player.UnityPlayer.resume(Unknown Source)
        at com.unity3d.player.UnityPlayerActivity.onResume(Unknown Source)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1249)
        at android.app.Activity.performResume(Activity.java:6102)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3167)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3223)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
        at android.app.ActivityThread.access$1200(ActivityThread.java:152)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5538)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
10-03 10:56:20.630 3051-3076/? E/ReportTools: This is not beta user build
10-03 10:56:20.710 3051-3175/? E/InputDispatcher: channel '772378 io.ionic.starter/com.unitycaller.ionic.UnityPlayerExtendedActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

And finally the app closes.

juan9506 commented 5 years ago

I managed to solve this by changing the dependencies in the build.gradle of the android and unity modules to 3.0.1:

dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }

Now it works perfect when I run it from android studio, but, when I run it from cordova with cordova run android I keep getting the same error. I have changed everything as stated here: #1 but the app just closes. It seems like it doesn't include the unity project in the build because the app is only 5mb. And if I run it from android studio works perfect again and the app is 35mb. Do you know what can be causing this issue? Finally, thanka a lot man, you are a live saver.

yasirkula commented 5 years ago

You have to generate the final output with Android Studio because cordova run android doesn't include the Unity app as you've suggested.

juan9506 commented 5 years ago

Hi again, I noticed that cordova does build it with the unity project too, but the apk is inside an extra folder called "debug". Now the ionic 1 example project is working perfectly in all devices, but when I try to apply this to an existing ionic 1 app, the unity side opens just on some devices, and in the others, I get the same error No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() I have tried everything, leaving only the armeabi-v7a, or leaving also the x86 folder, but anything works. Do you have any idea of what can be causing the error in some devices? having in mind that the example project (ionic 1 as well) works perfectly with the same unity project on all devices.

yasirkula commented 5 years ago

You are still building the final APK via Android Studio, right? In that case, if you left only armeabi-v7a libraries in your Android Studio project, I can't see any reasons for this error to occur, sorry :/

juan9506 commented 5 years ago

Hi again, I still don't figure what is causing this error on some devices. I have found this guides of how to overcome this kind of error, but when I try to apply it to your plugin, it doesn't work, maybe because I'm aplying it on the wrong section. Can you please take a look at this short guides and maybe see if that can fix this kind of error? http://mizoguche.info/2015/01/unity_android_plugin/ (this one just added a try-catch when calling the method. https://blog.csdn.net/ouyang_peng/article/details/52997698 (and this one renames the packages, but we don't have that kind of packages because they are inside the unity-classes.jar file, so I can't rename them) Maybe I'm doing that in the wrong section.

juan9506 commented 5 years ago

I finally solved this problem. It was caused because my project was creating more folders like x86, x86_64, armeabi after compiling it with cordova build android so I decompiled the .apk file, then I deleted all those folders only leaving the armeabi-v7a folder, then I recompiled that and it works perfectly now.