Xamarin. Android package Apk, xamarin. androidapk

Source: Internet
Author: User

Xamarin. Android package Apk, xamarin. androidapk

Because most of the content comes from the Xamarin official website, so this article is defined as a translation, original address: http://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/
Reprinted please indicate the source: http://blog.csdn.net/supluo/article/details/43950105
I have a blog App. I usually go to the toilet and read two articles before going to bed. I hope you can support it! Http://blog.csdn.net/supluo/article/details/43489475
After an application is tested for encoding, it should be packaged and released. The packaging of Xamarin. Android requires the following steps:
1. Compile the program in Release Mode
-- This step includes setting attributes of some applications.
2. Create a private key
-- Apk can be run on the mobile phone only after a digital visa is required. During debugging, the compiler uses a debug by default. keystore (usually in C: \ Users \ {pc name }\. android path;
Therefore, in this step, we need to create a private key for signing the apk (this key cannot be discarded, or signature issues may occur in subsequent upgrades ). This step usually only needs to be done once, that is, a key can be reused.
3. Sign the Apk
-- Use the private key to digitally sign the Apk
4. Perform Zipalign operations on the Apk
-- Zipalign is actually a tool included in the Android SDK. It can optimize packaged applications and make interaction more effective at runtime. Xamarin. Android checks when running and does not allow Apk running without zipaligned operations.
The Steps 3 and 4 are different on Xamarin Studio and Visual Studio.
1. Compile the program in Release Mode
To compile a program in Release mode, follow these steps:
1) set the running mode to Release (on the toolbar at the top of the compiler ).
-- This step prevents users from using ADB or other tools on the device for debugging.
2) define the program icon
-- An app icon should be specified for each Android program. Although this is not necessary at the technical level, it is required in some application markets, such as Goole Play.
3) set the version number
-- This step is to initialize or update the version information. This is important for future program updates and to ensure that users know the version of the application they are installing.
4) set Linker
-- Linking is a unique step of Xamarin. Android. It can greatly reduce the final APK size by removing unused code.
5) Compile
-- This step will integrate code and resources into an APK for quasi-local signature.
During release, we usually need to set Application (Debuggable = false );
Here we have the simplest method to add the following code to AssemblyInfo. cs (under the Properties directory of the project:
# If DEBUG
[Assembly: Application (Debuggable = true)]
# Else
[Assembly: Application (Debuggable = false)]
# Endif
2. Specify the program icon

Set the attribute in AssemblyInfo. cs: [assembly: Application (Icon = "@ drawable/ic_launcher")]

In Xamarin Studio, right-click the Project and choose Project Options> Android Application. Set the value of Application icon on the right.

In VS 2012, the method is similar, but right-click the project and choose Properties> Android Manifest> Application Icon.

VS 2010 does not seem to have this setting, so you need to set the attribute.

Iii. specified version number

Here there are two confusing versionCode and versionName;

Android: versionCode -- this is an integer that represents the version of the application. Most applications use 1 as the initial version value, which is incremented at each release.

This value has nothing to do with android: versionName (see the following description ). Neither the application nor the Publishing Service displays this value to the user.

Android: versionName -- this is a string that will be displayed to users in such app markets as Google Play. This string is not used internally by Android, which can be a string value that helps users identify applications installed on their devices.


4. Compile the program in Relase Mode

Before using Relase, it is very important to set The Linker, The linker in Xamarin. android will use static analysis to determine which assemblies, types, and type members are used or referenced by a Xamarin. android application. the linker will then discard all the unused assemblies, types, and members that are not used (or referenced ). this can result in a significant operation ction in the package size.

The above English section illustrates the role of Linker, which is not very difficult. Let's take a closer look at what it means.

The following is an example of Hello World:

Configuration

Xamarin. Android 4.2.5 Size

None

17.4 MB

SDK Assemblies Only

3.0 MB

That is, we create a new Hello World project. If we do not set anything, the size of the compilation will be 17.4 MB, but if we set it to SDK Assemnblies Only, the APK size will be changed to 3 MB, reduced by 83%.

Configuring Linker may have some side effects, so it is important to perform repeated tests after setting Linker, and these tests should be performed on real devices.


In VS 2013, right-click the project and select Properties to enter the Linker settings. See



The red box contains three options:

  • None-This turns off the linker; no linking will be completed MED.
  • Sdk Assemblies Only-This will only link the assemblies that are required by Xamarin. Android. Other assemblies will not be linked.
  • Sdk and User Assemblies-This will link all assemblies that are required by the application, and not just the ones required by Xamarin. Android.

In Xamarin. Studio,




The above red box also has three options, which are actually the same as the options in VS2013.


  • Don't link-This turns off the linker; no linking will be med.
  • Link SDK assemblies only-This will only link the assemblies that are required by Xamarin. Android. Other assemblies will not be linked.
  • Link all assemblies-This will link all assemblies that are required by the application, and not just the ones required by Xamarin. Android.

This article also involves an introduction to Linker: http://blog.csdn.net/supluo/article/details/38943123

After configuring Linker, You can compile the program. After compilation, you can use the private key created previously to sign the program. Of course, we can also create a secret key for signature during the release process after the operation.

First come here, some work matters need to be handled, and then make up later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.