How to dynamically load android so files, how to compress apk size, androidapk

Source: Internet
Author: User

How to dynamically load android so files, how to compress apk size, androidapk

Android compression tool set instructions

1. Introduction to toolsets (Project address: https://github.com/liyuming1978/NativeLibCompression)

Android compression tool set provides a very simple method, which can provide a higher compression ratio than the original Zip file of Android to store so files in the application (later versions can also support compression of dynamic loaded jar packages, and game resource files). At the same time, it provides a method to update and download compressed files in the application network, so that the application can store some so files to the cloud, reducing the size of the application.

Up to 50% space savings!

 

On the cloud testing platform, we tested 158 terminals, including 2.3 to 4.4 system versions.

100% pass the test!

 

Extract 8 m files within 1 s

Compression principle: the compression tool will compress all so files to the assert directory using the LZMA algorithm. When the application is started for the first time, it will decompress the files to the private directory of the application.

 

Ii. Composition of tool sets

The tool set is an installer. We recommend that you install it in the default path. If you install it in program files in win7, you may have read and write permissions, resulting in some exceptions.

After installation, You can see four directories that contain the source code.

The four directories after installation are as follows:

ApkLibComrepss is the source code of the java command line program. In the bin subdirectory of this directory, you can find ApkCompress. jar. This file can be used to convert a common apk file to a compressed apk file.

CompressDemo is a sample code. You can refer to this code to learn how to integrate the compressed SDK.

DecRawso is a compressed SDK. Your development project must reference This SDK and make some source code modifications to integrate the compression function.

RawsoCreator is a conversion tool in windows. It is generally not used and is only used for debugging and secondary development of the compression SDK.

3. How to integrate the compression SDK

Open CompressDemo and use this project as an example to explain how to integrate the compression SDK.

1. first introduce the DecRawso Project

2. Then you need to call it at the very beginning of your project.DecRawso. NewInstance. In this demo project, this method is called in OnCreate of MainActivity. java. This method creates a unique instance for decompression. Note: This method is asynchronous, so you can pass in a handler to receive messages completed by asynchronous decoding. If the showProgress parameter is set to true at the same time, A progress dialog box is generated in the SDK to block the main process. DecRawso is not recommended. newInstance (mContext, null, false); method, this method does not accept any messages, and there is no progress dialog box, decompression will be automatically completed in the background, the first time the application loads so, it is blocked until the backend decompression is completed. Therefore, if the blocking time is too long, the application may not respond.

3. how to modify the load so file: all systems. change loadlibrary (***) to external System. load (DecRawso. getInstance (). getPath ("***");
The new version can be omitted in this step. The sdk will modify the libaray loading path of the system. Generally, the system upgrade will not go wrong (informal code, with a low probability that the new Code will be modified with the android upgrade ), if it is convenient, use System. load (DecRawso. getInstance (). getPath ("***")

 

After these steps, the compressed SDK has been integrated into the project.

 

4. How to compress and publish an APK

Use ApkCompress. jar to compress and publish the APK. This is a command line tool. Generally, this command is used to run ComPressApk on the command line. jar-a C:/my/test.apk-k c:/key *** ### alias-x86http: // www.test.com (you can also run java-jarComPressApk. jar)

-A is followed by the apk path, which may not be the full path

-K is followed by the signature file [key storepasskeypass alias name]. The key can be not a full path name (if the name is not written, it is CERT by default)

-X86 indicates that the x86 library files need to be stored in the cloud, followed by a link starting with http: //, and the actual storage location should beHttp://www.test.com/cloudrawso_x86

After the command is executed, test_compressalign.apk will be generated. This apk is the compressed apk.

V. Development Mode and compression mode

To facilitate development, you can also do not compress the so and run the apk normally during the development process (after the source code is modified to support compression, the compressed SDK automatically determines whether a compressed package exists. If no compressed package exists, the loaded path is restored to the default android path. Therefore, the most convenient development is to integrate the code first. The development process is the same as the original one (without compression), and the apk is compressed at the time of release.

6. Hybrid calling of X86 and ARM Libraries

During development, some third-party libraries do not have the x86 version. Generally, ISV does not place the arm third-party library in the x86 directory, library shortage may occur during actual operation. When the library is missing, the compressed SDK will automatically decompress the arm package on the x86 device to avoid library shortage. (Only the missing library is loaded, and the library files are inconsistent)

However, this will obviously lead to low running efficiency. If the third-party so and x86 libraries do not reference each other at all (that is, these libraries are called using JNI on the java layer, the native layer does not call each other). You can copy the third-party library of arm to the x86 directory, so that no library is missing. Of course, this situation will lead to redundant copies of the arm library. In the previous zip compression case, the compressed package will become larger, but in the case of new LZMA compression, the library size will not increase at all, because LZMA compression has a large dictionary, it can compress several associated files as much as possible. If the files are identical, LZMA compression will be basically the same as that of a single file. For example




How to reduce the size of the apk package android

The apk size is directly related to the file size of your project. The most closely related is the image size. If you need to adapt to multiple mobile phones for one apk, you 'd better create only one set of images. In addition, the image size should be compressed to ensure the quality of the image display, optimize image storage space as much as possible

I would like to teach you how to dynamically load apk on android

In fact, there is a very practical problem, that is, if you re-create a function and it takes less time to reuse a function than you did to reuse it, is reuse valuable, I have long understood the above problem, but I do not know how to understand it. Reuse is something in the lab, but it doesn't matter. Your problem is to decompile xml in android. If you have to go all the way and don't want other implementations.
 

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.