1

Can you tell me what I need to do to get the APK through the console?
How do I check that all the needed tools are installed?
And which command or set of commands will create the APK file?

I can create an APK file from a Xamarin project using the GUI. That is, all the necessary components are installed.
I need to automate this process using CMD or PowerShell.

I've tried many options. The only one that doesn't give errors is:

"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" .\ProjectFolder\ProjectName.csproj ^
  /t:Restore;Build;Publish ^
  /p:Configuration=Release ^
  /p:Platform=AnyCPU ^
  /p:AndroidPackageFormat=apk ^
  /p:AndroidCreatePackage=true ^
  /p:AndroidKeyStore=true ^
  /p:AndroidSigningKeyStore=".\ProjectFolder\Certificates\ProjectName.keystore" ^
  /p:AndroidSigningStorePass="MyPass" ^
  /p:AndroidSigningKeyAlias="ProjectName" ^
  /p:AndroidSigningKeyPass="MyPass"

This completes with no errors, but the APK still does not appear.

Part of the .csproj file:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0A8D55C4-...}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-...};{FAE04EC0-...}</ProjectTypeGuids>
<TemplateGuid>{c9e5eea5-...}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace>MyNamespace</RootNamespace>
<AssemblyName>ProjectName</AssemblyName>
<Deterministic>True</Deterministic>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>

Visual Studio 2022: 17.14.17
MSBuild: 17.14.23.42201

New contributor
tunkimi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

If OutputType is Library, MSBuild will never produce an .apk, it will only compile a DLL

That property must be:

<OutputType>Exe</OutputType>

Because Xamarin Android apps are executables that package native code + Mono runtime → .apk.

generate an APK from command line
Ensure the project is an Android Application, not a library

Set these properties in the .csproj (or confirm they exist):

<OutputType>Exe</OutputType>
<AndroidApplication>true</AndroidApplication>

If a dependent library project still has <OutputType>Library</OutputType>, that’s fine — only the main app project must be Exe

Use the correct MSBuild
/t:Restore;Build;SignAndroidPackage

SignAndroidPackage is the only MSBuild target that produces a signed .apk.

you can find signed apk here

ProjectFolder\bin\Release\android\com.xxxx-Signed.apk

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.