How to generate an .apk file from Xamarin.Forms Project
Issue in generating .APK file in Xmarin forms
OS:Windows 10
Tools:Microsoft Visual Studio Enterprise 2022 (64 位) 版本 17.0.2
step 1:完成发布应用所需的准备工作
Step 2:签名 .apk 文件
Step 3: 将.apk 文件分发给用户。
Step 1:Create a new Xamarin.Forms project with default project template
Try The Following Steps:
Go to Solution Explorer -> Android project (right click) --> Archive --> Distribute -- AdHoc --> Sign & Add Details --> Save As
Step 2:Prepare you application before generate an .apk file
Three Condition like below:
Release-You need to change Your Project Mode from debug to release.
Clean Project-
Build Project -
Compile-Rebuild your project.-Select Build > Rebuild Solution to verify that it builds successfully in Release mode. this step does not yet produce an APK.
Step 3:generate an .apk file
Step 3.1:Archive
Archive -Go to Solution Explorer -> Android project (right click) --> Archive --> Distribute -- AdHoc --> Sign & Add Details --> Save As
this step produce an com.companyname.androidappformassharetarget.apk. in path:
this step produce an APK.( sign not included)
正在将文件从“F:\stock\src\WinForm\AndroidAppFormAsShareTarget\AndroidAppFormAsShareTarget.Android\obj\Release\110\android\bin\com.companyname.androidappformassharetarget.apk”
复制到
“F:\stock\src\WinForm\AndroidAppFormAsShareTarget\AndroidAppFormAsShareTarget.Android\bin\Release\com.companyname.androidappformassharetarget.apk”
Step 3.2: Distribute
this step produce an APK(sign not included)
Archive -Go to Solution Explorer -> Android project (right click) --> Archive --> Distribute -- AdHoc --> Sign & Add Details --> Save As
3.2.1 file apk on disk:
this step produce an APK(sign included)
Archive -Go to Solution Explorer -> Android project (right click) --> Archive --> Distribute -- AdHoc --> Sign & Add Details --> Save As
C:\Users\Administrator2\AppData\Local\Xamarin\Mono for Android\Archives\
com.companyname.androidappformassharetarget.apk
or
3.2.1 play store:
The APK is Ready To Publish in Play Store
Detail
step 1:Change Your Project Mode from debug to release.
To change the build configuration, either:
From the Build menu, select Configuration Manager, then select Debug or Release.
or
On the toolbar, choose either Debug or Release from the Solution Configurations list.
AndroidAppFormAsShareTarget.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CB873F3F-556F-465D-8223-C23D8FBB88E5}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{6968b3a4-1835-46a3-ac5c-1ae33b475983}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace>AndroidAppFormAsShareTarget.Droid</RootNamespace>
<AssemblyName>AndroidAppFormAsShareTarget.Android</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>v12.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\drawable\xamarin_logo.png" />
<AndroidResource Include="Resources\drawable\icon_about.png" />
<AndroidResource Include="Resources\drawable\icon_feed.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AndroidAppFormAsShareTarget\AndroidAppFormAsShareTarget.csproj">
<Project>{A5363005-C1DE-4709-A422-EF3C82991F82}</Project>
<Name>AndroidAppFormAsShareTarget</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="TextFile1.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
Office doc:How to Set debug and release configurations in Visual Studio 22 Step by Step?
step 2: Archive
this step produce an APK.
right click your Android project and select "Archive..."
Step 3:Distribute
Step 4:AdHoc
Step 5:Sign
要执行这一步,是因为:
Android 系统要求安装的每个应用都必须使用应用开发者拥有的证书(即开发者用于存放私钥的证书)进行数字签名。
Android 系统利用该证书来识别应用作者并在应用之间建立信任关系。您用于签名的的证书无需由证书授权机构签名;
Android 系统允许您使用自签名证书为您的应用签名。
Step 6:Save As
F:\stock\ReadDZHRealTime\src\WinForm\AndroidApp\bin\Release
Issue in generating .APK file in Xmarin forms
Archive error
1.obj\Release\110\android\assets contains Java.Interop.dll but no debug symbols file was found.
s:
vs 2022 Right click on Project>Properties
Go to Android Options > Debugging Options. UNCKECK the Enable Developer Instrumentation box.
old
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
new
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>