xamarinmaui

"Code signing must be enabled to create an Xcode archive." when publishing for Android in .NET MAUI


I am developing an App in .NET MAUI with C# 8.0 and my first Build was rejected by both Google and Apple. I was able update the project configuration so that I can make an *.ipa file for Apple and they seem happy with it. However, now I am no longer to build a Bundle for Google.

I select one of my physical Android devices as target and I select the Release configuration. When I right-click on my project and select "Publish..." from the context menu, it starts a Build. It shows Android as target platform, which is correct and the process text says "Archiving App Bundle" which is fine, too. But the Build fails and the message showing up is:

>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_18.0\18.0.8303\tools\msbuild\iOS\Xamarin.Shared.targets(2901,3): error : Code signing must be enabled to create an Xcode archive.

Now the thing is: I am making this Build for Android and not for iOS. So, why is XCode involved?

Please find my slightly redacted project file down below.

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

    <PropertyGroup>
        <TargetFrameworks>net8.0-ios;net8.0-maccatalyst;net8.0-android34.0</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

        <OutputType>Exe</OutputType>
        <RootNamespace>[MY APP NAME]</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>disable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>[MY APP NAME]</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

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

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">12.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">27.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>

    <PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
        <ProvisioningType>manual</ProvisioningType>
        <CodesignKey>[MY VALID KEY]</CodesignKey>
        <CodesignProvision>[MY VALID PROVISION]</CodesignProvision>
    </PropertyGroup>

    <!-- iOS -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
        <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
        <CodesignResourceRules></CodesignResourceRules>

        <MtouchDebug>True</MtouchDebug>
        <ArchiveOnBuild>True</ArchiveOnBuild>
        <MtouchInterpreter>all</MtouchInterpreter>
        <PublishAot>False</PublishAot>
        <UseInterpreter>True</UseInterpreter>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
        <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
        <CodesignResourceRules></CodesignResourceRules>

        <MtouchDebug>True</MtouchDebug>
        <ArchiveOnBuild>True</ArchiveOnBuild>
        <MtouchInterpreter>all</MtouchInterpreter>
        <PublishAot>False</PublishAot>
        <UseInterpreter>True</UseInterpreter>
    </PropertyGroup>

    <!-- Android -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
        <AndroidPackageFormat>aab</AndroidPackageFormat>
        <Debugger>Xamarin</Debugger>
        <EnableLLVM>False</EnableLLVM>
        <AndroidUseAapt2>True</AndroidUseAapt2>
        <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

        <_MauiForceXamlCForDebug>True</_MauiForceXamlCForDebug>
        <UseInterpreter>False</UseInterpreter>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
        <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
        <Debugger>Xamarin</Debugger>
        <EnableLLVM>False</EnableLLVM>
        <AndroidUseAapt2>True</AndroidUseAapt2>
        <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
        <AndroidPackageFormat>aab</AndroidPackageFormat>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

        <_MauiForceXamlCForDebug>True</_MauiForceXamlCForDebug>
        <UseInterpreter>False</UseInterpreter>
    </PropertyGroup>

    <!-- Mac Catalyst -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-maccatalyst|AnyCPU'">
      <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <!-- Windows -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows10.0.19041.0|AnyCPU'">
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows10.0.19041.0|AnyCPU'">
      <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\ourappicon.png" Color="#C7DCF9" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Images\app_our_logo.png" Color="#C7DCF9" BaseSize="200,67" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\app_our_logo.png">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </MauiImage>

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

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

    <ItemGroup>
        <None Remove="appsettings.json" />
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Include="appsettings.json" />
    </ItemGroup>

    <ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
        <CustomEntitlements Include="aps-environment" Type="string" Value="development" Condition="'$(Configuration)' == 'Debug'" />
        <CustomEntitlements Include="aps-environment" Type="string" Value="production" Condition="'$(Configuration)' == 'Release'" />
    </ItemGroup>
    <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
        <BundleResource Include="Platforms\iOS\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" />
    </ItemGroup>

    <ItemGroup>
        <GoogleServicesJson Include="Platforms\Android\google-services.json" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Camera.MAUI" Version="1.5.1" />
        <PackageReference Include="Camera.MAUI.ZXing" Version="1.0.0" />
        <PackageReference Include="CommunityToolkit.Maui" Version="9.0.3" />
        <PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="4.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="Plugin.LocalNotification" Version="11.1.3" />
        <PackageReference Include="Shiny.Beacons" Version="3.3.3" />
        <PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" />
        <PackageReference Include="Shiny.Push" Version="3.3.3" />
    </ItemGroup>

    <ItemGroup>
        <!-- ... Here are two C# 8.0 library projects I am using ... -->
    </ItemGroup>

    <ItemGroup>
        <!-- ... All my non-image resources are here ... -->
    </ItemGroup>

    <ItemGroup>
        <MauiXaml Update="Resources\Styles\CommonStyles.xaml">
            <Generator>MSBuild:Compile</Generator>
        </MauiXaml>
    </ItemGroup>

    <ItemGroup>
        <!-- ... All my XAML files are here ... -->
    </ItemGroup>

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android34.0'">
        <PackageReference Include="Symbol.XamarinEMDK">
            <Version>8.0.0.9</Version>
        </PackageReference>
    </ItemGroup>

</Project>

Solution

  • I had an idea in this morning's subway commute that works but feels unsatisfying. I made a backup of my App's project file and then removed any reference to either iOS or Mac from the project file. This ensured that Visual Studio will not try to do anything with XCode as there is literally no reference to iOS left.

    I was able to create a new Bundle without issues. Surprisingly, the created Bundle was over 60% smaller than the last Bundle I built two weeks ago. The only thing that changed is my reduced configuration.

    If someone has a better option and I can work with a single configuration file, I would be very happy.