Java operation ant compresses and decompresses files and packages anroid applications in batches

Zip / tar compression and decompression

Java actually supports zip and other compression formats, but why do you use ant here?

There are two main reasons: 1 The class provided by Java does not support the path and file name with Chinese characters well enough. There will be garbled code when you decompress it with other third-party software. And ant Jar supports that the file name or path includes Chinese characters. 2. ant. Jar provides a powerful tool class, which is more convenient for us to compress and decompress. Precautions: 1 First of all, for skin or zip package similar to skin, in fact, the company may customize the end of the compressed package file according to its own regulations or requirements. In fact, most of them are still in the format of zip package The processing of the specific part is basically the same, so I won't repeat it. The example given in this paper already has the decompression of zip package and tar package 2. It should also be noted that in order to improve understanding, the zip / tar compression and decompression interface is added, In practical application, this part does not need a separate interface display (if decompression takes a certain time, in order to enhance the user experience, add a prompt box and progress bar), please write your own decompression management class for logical judgment and handle it separately. 3. During the test, you need to import the package to be decompressed into the sdcard directory (if it is other directories, please modify the path in the code)

Program main interface and decompression interface:

Next, extract the core code: layout file: ant zip xml:

AntZipActivity:

DozipActivity:

Decompression tool class ziputil:

Ant implements batch packaging of Android applications. Due to the company's operation and maintenance needs and the needs of application promotion, it often needs to correspond to 20 or 30 channels and generate applications with different channel packages one by one according to the normal method, which not only wastes time, but also greatly reduces the efficiency In the previous article, we talked about using ant to decompress zip / tar packages. In fact, ant tools not only have such functions, but also have more powerful functions in automatically calling programs to complete project compilation, packaging, testing, etc It is similar to the make script in C language to complete these batch tasks Unlike Makefile, ant is written in pure Java, so it has good cross platform

Here, I mainly talk about how to automatically build the tool ant, package applications in batches, and generate applications corresponding to different markets:

First, take a look at the Java project anttest for packaging and the Android project structure that needs to be packaged for publishing:

market. Txt to save the market identification to be packaged, such as:

Add channel names according to requirements in this document

Then take a look at the contents of the anttest class for batch packaging: Note: the red part needs to be modified:

Then there are the parts that need to be modified in the Android project:

1. Modify local SDK root directory in properties:

2. Modify ant The path and password of the signature file in properties (if required)

3. Modify androidmanifest xml. Temp copy androidmanifest XML, named androidmanifest xml. Temp changes the place to be replaced into a placeholder, which should be consistent with the placeholder constant in the packaging project anttest, such as < meta data Android: value = "@ Market @" Android: name = "umeng_channel" / > 4 Build. XML: < project name = "XXX" default = "help" >, XXX must be the Android project name

If the machine has not been configured with ant environment variables, you can configure them according to the following steps:

Ant environment variable settings:

There are two main environment variables used by ant under windows, ant_ HOME 、PATH。

Set ant_ Home points to the installation directory of ant.

Setting method:

% ant_ HOME%/bin; % ANT_ Add home% / lib to the path of the environment variable.

Setting method:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>