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?
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.”
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…
Haha, yeah almost everything to do with Android is messy
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
Here is what I have:
< ItemGroup>
< AndroidAsset Include="Assets\Content\ ** \ . " >
< /AndroidAsset>
< /ItemGroup>
And that is same method I used for WP8 and iOS contents.
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…
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
}