How to use Ant to package an Android project in a Linux system

Source: Internet
Author: User
Tags exit modify file permissions root directory linux

In fact, the Linux ant packaged Android project has a lot in common with the Windows ant packaged Android project, the process is basically consistent, the only difference is probably the operational problem, and then, I will give a detailed introduction to the Linux System packaging Android project, and briefly follow up on some of the problems that I have when I build the relevant environment.

The old rules, first list the tools to use.

A, JAVAJDK;

B, ant compressed file; (http://ant.apache.org)

C, ANDROIDSDK (http://developer.android.com/sdk/index.html)

D, the most important one, Baidu search (www.baidu.com)

The second is the relevant command to be used , which is also described at the beginning, where the command to use is very similar to the command under Windows (99% similarity)

1. Verify that the Java environment is configured correctly: Java

2. Verify that the Android environment is correct: Android

3. Verify that the ant environment is correct: ant-version

4. Compile generate build.xml and local.properties File command: Android update project-p/. (Description:/. Refers to this directory, so you should go to the root of the project when you execute the command)

5. Compile general apk, if you do not need to specify a specific certificate (key), execute ant debug at the root of the project, and an automatically debug signed apk is generated in the bin directory. If you want to use a specific certificate, the action is as follows:

A. Create a new file in the root directory of the project "Ant.properties", in which reference to the certificate and related information, specific wording:

#证书所在的路径, including the certificate name itself

Key.store=c:/users/cheng/desktop/key.key

#证书的别名

Key.alias=key

#证书的密码

key.store.password=123456

#别名的密码

key.alias.password=123456

#引入混淆文件

#proguard. config=proguard.cfg

6. General Packaging: Ant release

There are two modes, as described in 5, assuming we reference the key file, then we generate a signed apk, and it is well known that the Android system can only install signed apk,

In another case, there is no reference to the signature file, which can be packaged successfully, but cannot be installed directly.

7. The project refers to other library projects:

If the project simply refers to a third-party jar package, just put the jar package in the Libs folder and it's OK, and Ant will automatically add the Third-party jar to the package during the compilation process. But when our Android project is referencing other library projects, we should initially enter the Android update command with one more parameter--subprojects:

You find the error, do not worry, this is because the library does not support ant automatic compilation, we need to let it also support. Into the directory where the Library project is located, enter the command Android update lib-project-p./(note is lib-project); go back to the original project, enter the command "Android Update project--name menu Drawsample-p/--subprojects ", this is OK.

The above is the use, operation instructions, and then I will briefly record my environment when the problem encountered .

The construction of the environment mainly took a day and a half of the time, said long not long, short. Like the description above, song Dandan asked: How many steps does it take to put an elephant in a fridge? The answer is three steps, open the fridge door, put the elephant in the fridge, and close the fridge door. This shows that again difficult problem, as long as we follow a certain plan, can always solve the difficulties,

I also do this when I build this:

Before that, I know nothing about Linux, according to my situation, my first step is to familiarize yourself with the basic Linux system use, such as the use of terminals into a folder, the use of terminals to delete a file, directory, using a terminal decompression. ZIP file, use the terminal to view the configuration details of some environments, use the terminal to modify file permissions, and so on.

When we get to know this, we can start the operation in a ballpark.

The second step: Download the relevant tools, in order to reduce the workload, you can first check whether the computer has been configured with the relevant environment and to view their version, I suffer here, because the local configuration of the Java environment is 64-bit bytes, And I don't know that there are only 32-bit Android SDK underneath the Linux system, so I've been looking for 64-bit tools in my head, until the compile time to tell me that "can not find a reference to the library file", Baidu, said the problem is the library, you can download a compatible library, I looked for a long time before downloading a compatible library. Finally, I can compile it.

The third step: Configure environment variables, speaking of environment variables, that can be said, where to start? From the ant environment Configuration, Linux environment variable Configuration and window is not the same, why, window environment configuration is a graphical operation interface, That little mouse is enough, but Linux is not the same, this place is to use the command,

First of all:Export command, although this command can also be configured, but the configuration is temporary variables, that is, only in the current terminal is valid, the exit is not used, the second, Vim/etc/profile This is configured permanent, Inside can insert the environment, inserting the way is to move the mark, enter oneself to add place, press keyboard any key can enter insert mode, exit Insert mode of method also very see, press ESC First, then enter: WQ, finally don't forget to enter #source/etc/profile save. Then enter the ant–version Validation command. There are also similar configuration options for SDK variables.

To summarize the steps to configure ant:

(Apahce-ant-1.9.7-bin.tar.gz is the name of the file, specifically look at the actual download)

1, from the http://ant.apache.org download tar.gz version ant

2. Copy to/usr below

3, Tar-vxzf apahce-ant-1.9.7-bin.tar.gz decompression (TAR–VXZF is an order)

4, Chown-r root apahce-ant-1.9.7 change the permissions (root is admin identity)

5, Vi/etc/profile Modify system configuration file

At the bottom we will see a lot of environmental configuration, such as: Java_home and so on, so we follow gourd painting scoop

ant_home=/usr/apache-ant-1.9.7

Path= $PATH: $ANT _home/bin: $ANT _home/lib: $PATH

After the change, press the ESC key, input: WP command to exit edit mode

6, Source/etc/proifle immediately will be configured to take effect

7, ant-version test ant is effective

OK, ant is already configured, and there's one to configure, and that's the androidsdk configuration . As in 5, modify the system configuration file.

The specific wording is: ANDROID_HOME=/USR/ADT_BUNDLE_LINUX/SDK

Path= $PATH: $ANT _home/bin: $ANT _home/lib: $ANDROID _home/tools: $PATH

Verify that when you enter Android in the terminal, if you pop up a window that's OK, if not, restart the system.

The Fourth step: According to the relevant instructions before the implementation, but also the error, said in my project below find Project.properjects file, I was Meng, because I have ah, how could not it! I was depressed for five minutes, quietly for a moment, system is, after all, a system, at least in this regard he is smarter than me, he said no there must be no, this time eclipse came in handy, I opened Eclipse, import my project into, in the reference to the library operation, see the correct reference to the wrong path, OH , understand, the original is the path of the problem, how painful the understanding, I modified, referenced the correct address, in the project's root directory physiognomy execute command ant release, successful.

As of now, the whole process has been introduced, in fact, a lot of things are like this, even if a thing feel very difficult, feel is unreachable, even if it is an unknown field, as long as clear their own purposes, and then down-to-earth to Baidu, and constantly clarify their own ideas, many problems can be solved.

Finally, let's summarize: ant packaging is not very complex things, is the general download related tools, configure environment variables, execute the relevant commands, on these operational processes.

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.