C # using Xamarin to develop portable mobile apps advanced (8. Package build Android APK and compact size), with source code

Source: Internet
Author: User

PrefaceSeries Catalogue

C # uses Xamarin to develop portable mobile app catalogs

Source Address: HTTPS://GITHUB.COM/L2999019/DEMOAPP

You can star, feel free--

Say something..

Well, in front of all that, it's time to create an apk to play on the real machine.

What are you learning today?

Just one, how to pack and build an Android installable APK and compact size.

Body

I remember someone asked me before when I was writing an android article. Xamarin.android Why are you packing so big? A Helloword 20-30mb?

Well.. Today we are going to solve this problem.

Let's start by specifying an application icon.

1. Specify the application icon

We directly right-click on the Android project, properties. Select the Android list below:

In the application icon option, we can select an existing picture resource file and set it as an icon for the application.

It's done--isn't it simple.

2. Set the application version and name

VS2017 inside has been translated more perfect, I will not explain more. Directly as:

3. Streamline and shrink apk (key) 3.1 Cancel Rapid deployment

First we enter

We then check the following two items in the package attribute:(Note: This is canceled!!)

3.2 Setting up connectors, streamlining Xamarin references

Then we slide down to find the linker properties , set as follows:

Connection selection, SDK assemblies only. (Default is None)

The linker in Xamarin.android uses static analysis to determine which assemblies, types, and type members the Xamarin.android application uses or references. The linker then discards all unused assemblies, types, and members that are not used (or referenced). This results in a significant reduction in the size of our final application. For example, Microsoft's official HelloWorld example, the final size of its apk is reduced by 83%:

    • Configured as: none-Xamarin.android 4.2.5 size = 17.4 MB
    • Configured to: SDK components only-xamarin.android 4.2.5 size = 3.0 MB
3.3 Setting up Android Proguard

Proguard is an Android SDK tool for linking and blurring Java code. Proguard is often used to reduce the footprint of large additional libraries in the APK, such as the Google Play service, for smaller applications.

Proguard will delete unused Java bytecode, which will make the resulting application smaller.

Generally, using Proguard on small xamarin.android applications can typically reduce the size of about 24%

If you use Proguard on larger applications that have multiple library dependencies, you can typically achieve a larger size reduction.

Proguard is not a replacement for xamarin.android connectors. xamarin.android linker links managed code, while Proguard links Java bytecode.

The build process is to first use the XAMARIN.ANDROID linker to optimize the managed (C #) code in your application, and then use Proguard (if enabled) to optimize the apk at the Java bytecode level.

When the Proguard check is enabled , Xamarin.android runs the resulting apk proguard tool. The Proguard configuration file is generated and used by Proguard at build time.

Xamarin.android also supports custom proguardconfiguration build operations. You can add a custom proguard configuration file to your project, right-click it, and select it as a build operation.

Here, we use the default operation directly. That is, check it out:

4. Archive and publish the build apk

Well.. This is our last step,

after the third step is set up, we can archive it.

Operation:

This will jump to the archive interface, as follows:

We wait for it to be packaged and finished. After completion, the rear gear will have a green tick, such as:

Click Distribute to complete the final publish operation, such as:

We can choose Google Play's certificate, or create a temporary certificate on our own.

Here we create a temporary certificate. For example:

Click the + sign to create the certificate. and fill in the information, please remember the password you entered here.

Once created, we directly select the certificate you just created to distribute it.

When the certificate is selected, select Save As. Then select the storage path for the APK file.

Click Save, will let you enter the password of the certificate., we fill in the password just entered.

Wait for the build to finish, just fine.

at this point, we've completed the packaged thin compression and release process for the entire app.

written in the last

This article only explains the app packaging process, as a published application, of course, it is not so simple to finish.

To ensure security, though, we confuse Java code with Proguard, but our. NET code is not confusing. By decompressing the APK program decompile our DLL, the source code will be very easy to expose .

In the next chapter we will explain how to confuse US . NET code

C # using Xamarin to develop portable mobile apps advanced (8. Package build Android APK and compact size), with source code

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.