androidgithub-actionsmaui

.NET 8 MAUI Android publish CD failing, build number replacing android sdk


I am using the following .yml with GitHub Actions to deploy my .Net 8 MAUI application to the Google Play Store. I deployed a new version as recently as last Friday with no issues. However now when I attempt to deploy somehow the version number ${{ env.GITHUB_RUN_NUMBER_WITH_OFFSET }} (simply adding 500010 to the github build number due to previous versioning prior to implementing github ci/cd) is taking the place of my target android sdk in the aab causing Google play store to reject it with this error: Error: Target SDK of artifact is too low: <current version number>.

I haven't changed the yml since my last successful deployment. I'm using managedcode/MAUIAppVersion@v1 to version my code:

jobs:
  publish-android:
    runs-on: windows-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Setup .NET ${{ inputs.dotnet-version }}
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ${{ inputs.dotnet-version }}

      - name: Install MAUI Workloads
        run: dotnet workload install android maui

      - name: Restore NuGet Packages
        run: dotnet restore ${{ inputs.sln-file }} --configfile ${{ inputs.nuget-config }}
        env:
          TELERIK_NUGET_KEY: ${{ secrets.telerik-nuget-api-key }}

      - name: Decode Keystore
        id: decode_keystore
        uses: timheuer/base64-to-file@v1
        with:
          fileDir: '${{ github.workspace }}\${{ inputs.project-folder }}'
          fileName: 'tw-upload-android.keystore'
          encodedString: ${{ secrets.keystore-base64 }}

      - name: Generate run number with offset (CMD)
        shell: cmd
        env:
          NUM: ${{ github.run_number }}
        run: |
          set /a OFFSET=%NUM%+5000010
          echo GITHUB_RUN_NUMBER_WITH_OFFSET=%OFFSET%>> %GITHUB_ENV%

      - name: Version the app
        uses: managedcode/MAUIAppVersion@v1
        with:
          csproj: ${{ inputs.project-file }}
          version: ${{ env.GITHUB_RUN_NUMBER_WITH_OFFSET }}
          displayVersion: ${{ inputs.build-version }}.${{ github.run_number }}
          printFile: true

      - name: Publish .NET MAUI Android APK
        env:
          TELERIK_LICENSE: ${{ secrets.telerik-license }}
        run: |
          dotnet publish ${{ inputs.project-file }} -c ${{ inputs.build-config }} `
          -f ${{ inputs.dotnet-version-target}}-android `
          -p:AndroidPackageFormat=aab `
          -p:AndroidKeyStore=true `
          -p:AndroidSigningKeyStore="${{ github.workspace }}/${{ inputs.project-folder }}/tw-upload-android.keystore" `
          -p:AndroidSigningKeyAlias=${{ secrets.keystore-alias }} `
          -p:AndroidSigningKeyPass=${{ secrets.keystore-password }} `
          -p:AndroidSigningStorePass=${{ secrets.keystore-password }} `
          --no-restore

      - name: Upload APK to Google Play
        uses: r0adkll/upload-google-play@v1
        id: play_upload
        with:
          serviceAccountJsonPlainText: ${{ secrets.playstore-service-account }}
          packageName: ${{ inputs.package-name }}
          releaseFiles: ${{ inputs.project-folder }}/bin/${{ inputs.build-config }}/${{ inputs.dotnet-version-target }}-android/${{ inputs.package-name }}-Signed.aab
          inAppUpdatePriority: 1
          track: internal

My .csproj correctly targets <AndroidTargetSdkVersion>35</AndroidTargetSdkVersion>. I've tried setting <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="35" /> in my AndroidManifest.xml, but somewhere during the build it is taking the version number and setting it as the target sdk. My guess is that there's a new bug in MAUI, MSBuild, or Github Actions.

I haven't found anyone running into a similar issue yet though, so I wonder if this is from a new bug in the build. I can't see where I'm going wrong.


Solution

  • The problem was in setting <AndroidTargetSdkVersion>35</AndroidTargetSdkVersion> in the first place. MAUI automatically sets the target sdk based on the .net version you are building with. Net 8 - 34, Net 9 - 35, and if you specify the version like I did, MSBuild will often (but not always, which is why this took so long to figure out) get confused and replace the target sdk with the version number.

    All this started because I was attempting to target Sdk 35 but didn't initially realize that meant upgrading to Net9. After upgrading, I kept the unneeded property in my .csproj, and also tried to set it in the Android Manifest. After deleting the <AndroidTargetSdkVersion> and <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="35" /> the versioning worked as expected again.