Android application fails to start (error info included)

My MG Android project got built and deployed to a Nexus S emulator, but always fails with some errors. I am including the exception log and application output here, and am wondering if someone could help me figure out what the problem is…

=Below is the exception log:=

Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
at — End of managed exception stack trace —
at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at at dalvik.system.NativeStart.main(Native Method)
at Caused by: java.lang.reflect.InvocationTargetException
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:511)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at … 2 more
at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: Failed to find a valid GraphicsMode configuration —> OpenTK.Platform.Android.EglException: Failed to find a valid GraphicsMode configuration
at OpenTK.Platform.Android.AndroidGraphicsMode.ChooseConfig (Javax.Microedition.Khronos.Egl.EGLDisplay display) [0x0036e] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsMode.cs:192
at OpenTK.Platform.Android.AndroidGraphicsMode.Initialize (Javax.Microedition.Khronos.Egl.EGLDisplay display, Int32 version) [0x0000a] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsMode.cs:233
at OpenTK.Platform.Android.AndroidGraphicsContext.Init (OpenTK.Graphics.GraphicsMode mode, IWindowInfo win, IGraphicsContext sharedContext, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x000c5] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:133
at OpenTK.Platform.Android.AndroidGraphicsContext…ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext, GLVersion glesVersion, GraphicsContextFlags flags) [0x00028] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:104
at OpenTK.Platform.Android.AndroidGraphicsContext.CreateGraphicsContext (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext, GLVersion glVersion, GraphicsContextFlags flags) [0x00007] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:59
at OpenTK.Platform.Android.AndroidGameView.CreateContext () [0x00041] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:403
at OpenTK.Platform.Android.AndroidGameView.MakeCurrent () [0x00013] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:209
at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs eventArgs) [0x0000a] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:143
at — End of inner exception stack trace —
at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs) [0x00016] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:147
at OpenTK.Platform.Android.AndroidGameView.LoadInternal (System.EventArgs) [0x00003] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:293
at OpenTK.Platform.Android.AndroidGameView.SurfaceCreated (Android.Views.ISurfaceHolder) [0x00059] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:119
at Microsoft.Xna.Framework.MonoGameAndroidGameView.Android.Views.ISurfaceHolderCallback.SurfaceCreated (Android.Views.ISurfaceHolder) [0x00001] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:129
at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceCreated_Landroid_view_SurfaceHolder_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Views.ISurfaceHolder.cs:194
at at (wrapper dynamic-method) object.65492e41-d7d9-4587-820f-5c67f2e453d3 (intptr,intptr,intptr) <IL 0x00017, 0x00053>
at at md5cedead65730cfb9c4b33fbfd5914d87f.MonoGameAndroidGameView.n_surfaceCreated(Native Method)
at at md5cedead65730cfb9c4b33fbfd5914d87f.MonoGameAndroidGameView.surfaceCreated(MonoGameAndroidGameView.java:83)
at at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
at at android.view.SurfaceView.access$000(SurfaceView.java:81)
at at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
at at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
at at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
at at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at at android.os.Handler.dispatchMessage(Handler.java:99)
at at android.os.Looper.loop(Looper.java:137)
at at android.app.ActivityThread.main(ActivityThread.java:4424)
at … 5 more

=Below is the application output:=

[Mono] DllImport attempting to load: ‘/system/lib/libc.so’.
[Mono] DllImport loaded library ‘/system/lib/libc.so’.
[Mono] DllImport searching in: ‘/system/lib/libc.so’ (’/system/lib/libc.so’).
[Mono] Searching for ‘gettid’.
[Mono] Probing ‘gettid’.
[Mono] Found as ‘gettid’.
[Mono] Assembly Ref addref MonoGame.Framework[0x2a2151e0] -> System.Core[0x2a2cc3a8]: 4
[Choreographer] Skipped 45 frames! The application may be doing too much work on its main thread.
Thread started: #4
[MonoGame] MonoGameAndroidGameView.CreateFrameBuffer
[Mono] DllImport attempting to load: ‘/system/lib/libc.so’.
[Mono] DllImport loaded library ‘/system/lib/libc.so’.
[Mono] DllImport searching in: ‘/system/lib/libc.so’ (’/system/lib/libc.so’).
[Mono] Searching for ‘uname’.
[Mono] Probing ‘uname’.
[Mono] Found as ‘uname’.
[Mono] DllImport attempting to load: ‘libEGL.dll’.
[Mono] DllImport error loading library ‘./libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/./libEGL.dll” not found’.
[Mono] DllImport error loading library ‘./libEGL.dll.so’: ‘dlopen failed: library “/data/app-lib/TheGame/libaot-libEGL.dll.so” not found’.
[Mono] DllImport error loading library ‘libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/libEGL.dll” not found’.
[Mono] DllImport error loading library ‘libEGL.dll.so’: ‘dlopen failed: library “/data/app-lib/TheGame/libaot-libEGL.dll.so” not found’.
[Mono] DllImport error loading library ‘libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/libEGL.dll” not found’.
[Mono] DllImport error loading library ‘./libEGL’: ‘dlopen failed: library “/data/app-lib/TheGame/./libEGL” not found’.
[Mono] DllImport loaded library ‘./libEGL.so’.
[Mono] DllImport searching in: ‘libEGL.dll’ (’./libEGL.so’).
[Mono] Searching for ‘eglGetCurrentContext’.
[Mono] Probing ‘eglGetCurrentContext’.
[Mono] Found as ‘eglGetCurrentContext’.
[MonoGame] Creating Color: 32 (8888), Depth: 24, Stencil: 0, Accum:32 (8888)
[MonoGame] Creating Color: 16 (5650), Depth: 24, Stencil: 0, Accum:16 (5650)
[MonoGame] Creating Color: 0 (0000), Depth: 24, Stencil: 0, Accum:0 (0000)
[MonoGame] Creating Color: 32 (8888), Depth: 16, Stencil: 0, Accum:32 (8888)
[MonoGame] Creating Color: 16 (5650), Depth: 16, Stencil: 0, Accum:16 (5650)
[MonoGame] Creating Color: 0 (0000), Depth: 16, Stencil: 0, Accum:0 (0000)
[MonoGame] Creating default mode
[MonoGame] Creating Color: 0 (0000), Depth: 0, Stencil: 0, Accum:0 (0000)
[Mono] DllImport attempting to load: ‘/system/lib/liblog.so’.
[Mono] DllImport loaded library ‘/system/lib/liblog.so’.
[Mono] DllImport searching in: ‘/system/lib/liblog.so’ (’/system/lib/liblog.so’).
[Mono] Searching for ‘__android_log_print’.
[Mono] Probing ‘__android_log_print’.
[Mono] Found as '_android_log_print’.
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: Failed to find a valid GraphicsMode configuration —> OpenTK.Platform.Android.EglException: Failed to find a valid GraphicsMode configuration
[MonoDroid] at OpenTK.Platform.Android.AndroidGraphicsMode.ChooseConfig (Javax.Microedition.Khronos.Egl.EGLDisplay display) [0x0036e] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsMode.cs:192
[MonoDroid] at OpenTK.Platform.Android.AndroidGraphicsMode.Initialize (Javax.Microedition.Khronos.Egl.EGLDisplay display, Int32 version) [0x0000a] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsMode.cs:233
[MonoDroid] at OpenTK.Platform.Android.AndroidGraphicsContext.Init (OpenTK.Graphics.GraphicsMode mode, IWindowInfo win, IGraphicsContext sharedContext, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x000c5] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:133
[MonoDroid] at OpenTK.Platform.Android.AndroidGraphicsContext…ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext, GLVersion glesVersion, GraphicsContextFlags flags) [0x00028] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:104
[MonoDroid] at OpenTK.Platform.Android.AndroidGraphicsContext.CreateGraphicsContext (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext, GLVersion glVersion, GraphicsContextFlags flags) [0x00007] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGraphicsContext.cs:59
[MonoDroid] at OpenTK.Platform.Android.AndroidGameView.CreateContext () [0x00041] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:403
[MonoDroid] at OpenTK.Platform.Android.AndroidGameView.MakeCurrent () [0x00013] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:209
[MonoDroid] at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs eventArgs) [0x0000a] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:143
[MonoDroid] — End of inner exception stack trace —
[MonoDroid] at Microsoft.Xna.Framework.MonoGameAndroidGameView.OnLoad (System.EventArgs) [0x00016] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:147
[MonoDroid] at OpenTK.Platform.Android.AndroidGameView.LoadInternal (System.EventArgs) [0x00003] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:293
[MonoDroid] at OpenTK.Platform.Android.AndroidGameView.SurfaceCreated (Android.Views.ISurfaceHolder) [0x00059] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:119
[MonoDroid] at Microsoft.Xna.Framework.MonoGameAndroidGameView.Android.Views.ISurfaceHolderCallback.SurfaceCreated (Android.Views.ISurfaceHolder) [0x00001] in i:\MonoGame\MonoGame.Framework\Android\MonoGameAndroidGameView.cs:129
[MonoDroid] at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceCreated_Landroid_view_SurfaceHolder
(intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Views.ISurfaceHolder.cs:194
[MonoDroid] at (wrapper dynamic-method) object.53111b0d-bb58-4ffd-ac63-2b256d6bb75d (intptr,intptr,intptr) <IL 0x00017, 0x00053>
[AndroidRuntime] Shutting down VM

Maybe your emulator is not GPU accelerated? I recommend avoiding emulators as they are far from optimal for development.

Thanks Nezz! I’ll make sure to test it again with a Nexus device later today. Meanwhile, what do you think is going wrong with these error messages in the application output?

[Mono] DllImport attempting to load: ‘libEGL.dll’.
[Mono] DllImport error loading library ‘./libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/./libEGL.dll” not found’.
[Mono] DllImport error loading library ‘./libEGL.dll.so’: ‘dlopen failed: library “/data/app-lib/TheGame/libaot-libEGL.dll.so” not found’.
[Mono] DllImport error loading library ‘libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/libEGL.dll” not found’.
[Mono] DllImport error loading library ‘libEGL.dll.so’: ‘dlopen failed: library “/data/app-lib/TheGame/libaot-libEGL.dll.so” not found’.
[Mono] DllImport error loading library ‘libEGL.dll’: ‘dlopen failed: library “/data/app-lib/TheGame/libEGL.dll” not found’.
[Mono] DllImport error loading library ‘./libEGL’: ‘dlopen failed: library “/data/app-lib/TheGame/./libEGL” not found’.

I think that is the pertinent bit in the logs. As Nezz implies, I think you can edit the emulator image settings and enable GPU acceleration.

I’ve also read good things about this emulator: https://www.genymotion.com/

Google’s Android emulator by default only supports OpenGL ES 1.1 in software. To use OpenGL ES 2.0 (required by MonoGame) you need to enable GPU acceleration.

The Visual Studio Android emulator (same as the Xamarin Android emulator) provides hardware acceleration and launches a lot faster than Google’s emulator.

Thanks @Nezz, @Aranda and @KonajuGames! I tested the game with a Nexus 7 device and it seems that problem is now gone (or bypassed?). However there is a new issue that prevents the game from running: Xamarin Studio doesn’t support the “Content” build action on Android, resulting in the error message below:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Fonts/titleFont asset as a non-content file! —> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. —> Java.IO.FileNotFoundException: Exception of type ‘Java.IO.FileNotFoundException’ was thrown.

And it seems Xamarin hasn’t figure out a way to solve this:
http://developer.xamarin.com/guides/android/under_the_hood/build_process/
“Content
The normal Content Build action is not supported (as we haven’t figured out how to support it without a possibly costly first-run step).
Starting in Xamarin.Android 5.1, attempting to use thw @(Content) Build action will result in a XA0101 warning.”

I wonder if there is a way to fix this problem?

For Android, you should use the BuildAction of AndroidAsset (and Do not copy) instead of Content. Also your whole Content folder should be inside an Assets folder at the root of the Android project.

Thanks so much for your help @Aranda! I followed your instructions but the same error is still there. The content files were built using the old MG content pipeline project with the Android configuration. I’ve been using that pipeline project to build content for the iOS version of my game, so the content itself shouldn’t be the cause of this problem. I really don’t know what to do now. Never expected that porting an existing project to Android could be this messy… :frowning:

Haha, yeah almost everything to do with Android is messy :stuck_out_tongue:

I also had this problem and found that text searching through the .csproj file for “<Content” found the offending item. In my case it wasn’t actually a content file - I think it was the AndroidManifest.xml which can have a BuildAction of None

text searching for what? :smile:

Oh damn, “Content”, with the opening angle brace, but not the closing one. Forums must have interpreted it as malformed HTML :slight_smile:

[EDIT] But failing that, check every single file in the whole project to make sure Build Action is not set to Content.

Here is what I have:
< ItemGroup>
< AndroidAsset Include="Assets\Content\ ** \ . " >
< /AndroidAsset>
< /ItemGroup>
And that is same method I used for WP8 and iOS contents. :smile:

Ok, that’s the game’s content files, but the error you are getting implies there is some other file with:
< Content Include="…">

Well it was “Content” but I manually changed it to “AndroidAssets”… If I set it back to “Content” the build action will become “Content”…

Also I checked the .apk file using WinRar. The Assets/Content folder, together will all the .xnb files, is in there…

I meant check inside the .csproj file for any other occurances of <Content Include="...">, ie files that are not assets. That was the problem for me anyway.

I checked all over the .csproj file and there is no other occurrence of < Content Include = “…”>…

I wonder if the “Content” build action has ever been available in the previous versions of Xamarin? The build action for the contents of the WP8 version and iOS version of my game is “Content”, and it seems the “AndroidAssets” build action is not working well with MG content files… :frowning:

I recently upgraded my Xamarin.Android version and this error just started appearing, so I’m guessing that Content build actions were just ignored before. When I removed the one on my AndroidManifest.xml, the error went away. That’s why I assumed you must have a file in one of your projects that is still set to Content. If not, then I’m not sure, sorry.

I just looked more closely at your error log - perhaps the Content build action error is a red herring because this looks like the actual problem. I’m pretty sure Android file system is case-sensitive, so make double sure you have Assets/Content/Fonts/titleFont.xnb (with that case) inside the APK file.

Thanks so much @Aranda! I think I kind of figured out why: I set the root directory of Game.ContentManager to “Assets/Content”, while it was originally set by the MG template as:
Content.RootDirectory = “Content”;

I changed it back and the loading errors of those xnb files are gone. But it seems there are still other data loading issues caused by this inconsistent file structure… Guess I’ll have to fix them later…

Quick question: do I need to change all the ContentManager initialization lines to the Android way? I.e. something like this?
if (content == null) {
#if !ANDROID
content = new ContentManager (Game.Services, “Content”);
#else
content = new ContentManager (Game.Services, “Assets/Content”);
#endif
}

Thanks very much again for your help! :smile: