"AndroidGameActivity" not found within namespace "Microsoft.Xna.Framework"

I’m not sure if this is a bug in the framework or a problem on my end.

Yesteday I began porting my game engine over to Android. The engine itself is a class library with a dependency on the MonoGame.Framework.DesktopGL package. It compiles and runs fine on Windows.

After creating a new fresh Android MonoGame project and adding a dependency to the aforementioned library, the project gives me a “type or namespace could not be found” error with the AndroidGameActivity class. The dependencies seem to be installed correctly, and I can load and reference other types within the Microsoft.Xna.Framework namespace, just this one class isn’t located.

I’ve tried several things today, including removing all references to my engine from the new project, but the class doesn’t seem to be loading. Is there any known fixes to this?

If the game engine should run on Android, it needs a dependency on MonoGame.Framework.Android, not DesktopGL.

I also found the same problem.

The “MonoGame.Framewrok.Portable” package that existed until MonoGame 3.7.1 no longer exists in MonoGame 3.8.0, so I was using “MonoGame.Framewrok.DesktopGL” instead.

However, in the latest NuGet development version (MonoGame 3.8.1.1893), if you use “MonoGame.Framewrok.DesktopGL” as shared library and “MonoGame.Framewrok.Android” as executable project Android" as an executable project, it seems to cause a build error.

1 Like

I had the same issue recently, Possibly it’s a ‘feature’ of nuget. VS2019 gets the two libraries mixed up, it ignores the first reference and validates the main app against the Monogame from the library project. I could fix it by adding <PrivateAssets> inside the library project file. I have no idea if that’s correct.

   <ItemGroup>
    <PackageReference Include="MonoGame.Framework.Portable.9000" Version="3.8.9006">
      <PrivateAssets>All</PrivateAssets> 
      <NoWarn>NU1701</NoWarn>
    </PackageReference>
  </ItemGroup>