Part 1 - Preparing an Application for Release After an application has been coded and tested, it is necessary to prepare a package for distribution. Preparing the package consists of the following steps: Compile For Release – This step involves setting some application attributes. Create a Private Key – This step needs to be performed only once. A private key is necessary to digitally sign the APK. After the private key has been prepared, this step can be skipped for future release builds. Sign the APK – This step involves signing the APK with the private key that was created in the previous step. Zipalign the APK – Zipalign is an optimization process that is performed on an application. It enables Android to interact more efficiently with the APK at runtime. Xamarin.Android conducts a check at runtime, and will not allow the application to run if the APK has not been zipaligned. The last two steps of preparing an application for release differ in Xamarin Studio and Visual Studio. The difference between these two steps will be covered in more detail below. Compile the Application for Release The first step in distribution is to compile the Xamarin.Android application for release. Compiling for release involves: Disable Debugging – This prevents users from trying to debug the application on a device by using ADB or other tools. Specify the Application Icon – Each Xamarin.Android application should have an application icon specified. It is not technically required; however, some markets, such as Google Play, require it. Version the Application – This step involves initializing or updating the versioning information. This is important for future application updates and to ensure that the users are aware of which version of the application they have installed. Configure the Linker – Linking is a step that is specific to Xamarin.Android and can substantially reduce the size of the final APK by removing un-used code. Compile – This step will compile the code and assets into an APK that is ready for signing. Each of these steps is described in more detail below. Disable Debugging
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Part 1 - Preparing an Application for Release
After an application has been coded and tested, it is necessary to prepare a package for distribution.
Preparing the package consists of the following steps:
Compile For Release – This step involves setting some application attributes.
Create a Private Key – This step needs to be performed only once. A private key is necessary to
digitally sign the APK. After the private key has been prepared, this step can be skipped for future
release builds.
Sign the APK – This step involves signing the APK with the private key that was created in the
previous step.
Zipalign the APK – Zipalign is an optimization process that is performed on an application. It
enables Android to interact more efficiently with the APK at runtime. Xamarin.Android conducts a
check at runtime, and will not allow the application to run if the APK has not been zipaligned.
The last two steps of preparing an application for release differ in Xamarin Studio and Visual Studio. The
difference between these two steps will be covered in more detail below.
Compile the Application for Release
The first step in distribution is to compile the Xamarin.Android application for release. Compiling for release
involves:
Disable Debugging – This prevents users from trying to debug the application on a device by using
ADB or other tools.
Specify the Application Icon – Each Xamarin.Android application should have an application icon
specified. It is not technically required; however, some markets, such as Google Play, require it.
Version the Application – This step involves initializing or updating the versioning information. This
is important for future application updates and to ensure that the users are aware of which version of
the application they have installed.
Configure the Linker – Linking is a step that is specific to Xamarin.Android and can substantially
reduce the size of the final APK by removing un-used code.
Compile – This step will compile the code and assets into an APK that is ready for signing.
Each of these steps is described in more detail below.
Disable Debugging
During development of an Android application, debugging is performed with the use of the Java Debug
Wire Protocol (JDWP). This is a technology that allows tools such as ADB to communicate with a JVM for
the purposes of debugging. JDWP is turned on by default for Debug builds of a Xamarin.Android
application. While JDWP is important during development, it can pose a security issue for released
applications.
Note:
Always disable the debug state in a released application as it is possible (via JDWP) to gain full access to
the Java process and execute arbitrary code in the context of the application, if this debug state is not
disabled.Inside the Android manifest exists the attribute android:debuggable, which controls whether
or not the application may be debugged. It is considered a good practice to set the android:debuggable
to false.
The simplest way to do this is by adding a conditional compile statement to AssemblyInfo.cs:
#if DEBUG
[assembly: Application(Debuggable=true)]
#else
[assembly: Application(Debuggable=false)]
#endif
Specify The Application Icon
It is strongly recommended that a Xamarin.Android application should specify an application icon. Some
application marketplaces will not allow an Android application to be published without one.
The Icon property of the ApplicationAttribute is used to specify the application icon for a
Xamarin.Android project. This attribute can be declared in the file Properties\AssemblyInfo.cs, as