dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.83k stars 1.67k forks source link

Error Building Android App with Microsoft.Maui.Controls.Maps #23357

Open azrellie opened 1 week ago

azrellie commented 1 week ago

Description

Currently trying to load a map control onto my Android phone, but I get this error when building the app:

Severity    Code    Description Project File    Line    Suppression State   Details
Error   AMM0000 C:\Users\username\source\repos\maui maps android\maui maps android\obj\Debug\net8.0-android\lp\166\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.base' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\Users\username\source\repos\maui maps android\maui maps android\obj\Debug\net8.0-android\lp\167\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.common' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\Users\username\source\repos\maui maps android\maui maps android\obj\Debug\net8.0-android\lp\169\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.tasks' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\Users\username\source\repos\maui maps android\maui maps android\obj\Debug\net8.0-android\lp\168\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.maps' used in: AndroidManifest.xml, AndroidManifest.xml.

    Attribute meta-data#com.google.android.gms.version@value value=(2131165184) from AndroidManifest.xml:14:62-88
    is also present at AndroidManifest.xml:23:13-66 value=(@integer/google_play_services_version).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:14:5-91 to override.
Directory 'obj\Debug\net8.0-android\lp\166' is from 'play-services-base.aar'.
Directory 'obj\Debug\net8.0-android\lp\167' is from 'play-services-basement.aar'.
Directory 'obj\Debug\net8.0-android\lp\169' is from 'play-services-tasks.aar'.
Directory 'obj\Debug\net8.0-android\lp\168' is from 'play-services-maps.aar'.   maui maps android   C:\Users\username\source\repos\maui maps android\maui maps android\obj\Debug\net8.0-android\AndroidManifest.xml 14

I followed the setup for Maui maps from this page: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/map?view=net-maui-8.0. I have looked to other places to find a solution, but nothing was working. I'm also calling UseMauiMaps() in the MauiProgram.cs file (after the ConfigureFonts method). Didn't resolve it. My project is targeting Android devices, and uses .NET 8. The version of Microsoft.Maui.Controls.Maps that I'm using is 8.0.61.

Here are the contents of some of the important stuff (if there is any files I need to show, please let me know):

csproj file:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

        <!-- Note for MacCatalyst:
        The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
        When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
        The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
        either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
        <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

        <OutputType>Exe</OutputType>
        <RootNamespace>maui_maps_android</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>maui maps android</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.companyname.mauimapsandroid</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.60" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.60" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Microsoft.Maui.Controls.Maps" Version="9.0.0-preview.5.24307.10" />
    </ItemGroup>

</Project>

AndroidManifest.xml file:


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:allowBackup="true" android:icon="@android:mipmap/sym_def_app_icon" android:roundIcon="@android:mipmap/sym_def_app_icon" android:supportsRtl="true">
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="xxxxxxyyyyyy" />
        <meta-data android:name="com.google.android.gms.version" android:value="2131165184" />
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>```
github-actions[bot] commented 1 week ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

jfversluis commented 6 days ago

You're using the .NET 9 preview version of the maps NuGet with the .NET 8 versions of the other NuGets. Change the maps one to: <PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.60" /> does that fix it?

azrellie commented 6 days ago

You're using the .NET 9 preview version of the maps NuGet with the .NET 8 versions of the other NuGets. Change the maps one to: <PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.60" /> does that fix it?

I did that, but that did not fix it. I also changed the version of some of the other packages I'm using. Here they are from the csproj file:

<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.60" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.60" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.60" />
jfversluis commented 5 days ago

Could you please add a reproduction project and upload that to a public GitHub repository so we can have a look?

Also I removed your API key from your initial post, you might want to reset that key as it has been published to a public site now and people might misuse it.

azrellie commented 5 days ago

Could you please add a reproduction project and upload that to a public GitHub repository so we can have a look?

Will do that in a moment.

Also I removed your API key from your initial post, you might want to reset that key as it has been published to a public site now and people might misuse it.

Oops, I forgot to remove that when copy and pasting stuff. Thanks though.

azrellie commented 5 days ago

I started with a clean Maui project, and followed the same setup from the .NET Maui Maps setup page. Same error would occur. But when I removed this part <meta-data android:name="com.google.android.gms.version" android:value="2131165184" /> in the AndroidManifest.xml file though, the program would load normally if I don't make a map in the xaml file. If I do make a map in the xaml file, then it all loads normally still, the map does too, but the map is just blank. I'm just creating a barebones map via this: <maps:Map x:Name="map"/>