Forum Discussion

SampsonYe's avatar
SampsonYe
Copper Contributor
Nov 23, 2021
Solved

How to build MAUI to apk?

i try publish,it can not work

  • SampsonYe 

     

    Using the dotnet cli you can build an apk using the following command:

     

    dotnet build -f net6.0-android

     

    The apk file will be built, and you can find it at <app-root-dir>/bin/release/net6.0-android/com.companyname.appname-Signed.apk

8 Replies

  • harie's avatar
    harie
    Copper Contributor

    To build a MAUI app to an APK, follow these steps: Open your MAUI project in Visual Studio. Switch to Android platform in the toolbar. Set the build configuration to Release (for production) or Debug (for testing). Check Android project settings: In project properties → Android Options → Packaging, you can set options like Fast Deployment. For Release builds, consider setting <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> in the .csproj file. Build the project: Go to Build → Build Solution. Locate the APK: After build, you can find the APK in bin\Release\net7.0-android\publish\ (or corresponding path depending on your MAUI/SDK version). Deploy or test: You can install it on an Android device or run it via Xamarin.UITest. 

     Tip: For testing, use Debug mode; for publishing, always build Release and sign the APK.

  • Anna_Doll's avatar
    Anna_Doll
    Copper Contributor

    To build a .NET MAUI app into an APK, follow these steps:

    1. Use the Command: Run this in your project directory:bashdotnet build -f:net6.0-android -c:Release

    2. Locate the APK: Find the APK at:bash<project-root>/bin/Release/net6.0-android/com.companyname.appname-Signed.ap 

    3. Optional Signing: For production, configure signing in your .csproj or manually sign the APK.

    This will generate a ready-to-deploy APK.

  • GameJonny's avatar
    GameJonny
    Copper Contributor

    SampsonYe Right click on the project and hit publish. Make sure you have the desired framework selected and it will create the archive.

     

    Not sure why MS felt the need to change this but still leave the View Archives option.

  • apkthrills's avatar
    apkthrills
    Copper Contributor
    Open a command prompt and navigate to the directory where your MAUI project is located.
    Run the following command:
    dotnet publish -c Release -r Android -p:PackageFormat=Apk
    This will create an APK file in the bin\Release\Android\ directory of your project.
    Here is a more detailed explanation of the steps:
    The dotnet publish command is used to build a .NET MAUI app.
    The -c Release option specifies that the app should be built in release mode.
    The -r Android option specifies that the app should be built for Android.
    The -p:PackageFormat=<a href="https://apkthrills.com/zombie-tsunami-mod-apk/">Apk</a> option specifies that the app should be packaged as an APK file.
    I hope this helps!
  • StrathdeeK's avatar
    StrathdeeK
    Copper Contributor

    SampsonYe 

     

    Using the dotnet cli you can build an apk using the following command:

     

    dotnet build -f net6.0-android

     

    The apk file will be built, and you can find it at <app-root-dir>/bin/release/net6.0-android/com.companyname.appname-Signed.apk

    • SampsonYe's avatar
      SampsonYe
      Copper Contributor

      StrathdeeK 

      Wowo  nice, it work!!

      just use dotnet cli can finish it

       

      but why VS 2022 Preview Can't publish suitable apk?

       

      • NicolasKrier's avatar
        NicolasKrier
        Copper Contributor

        SampsonYe 

        In the MAUI proj settings, there is a combobox/dropdownlist where you set your preferences
        See Android package section

         

        But when bundle (aab) is made, it generates the apk too at the same time.
        Check your bin\Release\net7.0-android folder

Resources