Recently, I am working on an e-book generation project. I need to automatically package an APK with different package names online based on the e-book content resources and add content information such as various marketing channels, to interact with the backend, one-click generation is required. Therefore, the Android project must be packaged and generated on the server. Because the server is a javastuserver and has no image interface, only one command line environment can be set up, run the ant script to package the file, find the information, and share with you the setup process based on your environment configuration.
Ant environment preparation
The simplest is to use:
The code is as follows: |
Copy code |
Sudo apt-get install ant
|
Or manually install:
1. Go to the Apache official website to download the latest version of ant: http://ant.apache.org /. Decompress the downloaded .tar.gz file:
The code is as follows: |
Copy code |
Tar-xf apache-ant-1.8.2-bin.tar.gz
|
2. Move the extracted file to/opt/: sudo mv apache-ant-1.8.2/opt/(sudo cannot be saved; otherwise, you do not have permission)
3. Configure the environment variable: sudo vim/etc/profile. Add the following blue font on the basis of the original:
The code is as follows: |
Copy code |
Export ANT_HOME =/opt/apache-ant-1.8.2 Export JAVA_HOME =/usr/lib/jvm/java-6-openjdk Export PATH = $ JAVA_HOME/bin: $ PATH: $ ANT_HOME/bin Export CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar |
4. Verify whether the installation is successful:
The code is as follows: |
Copy code |
Ant-version Apache Ant (TM) version 1.8.2 compiled on December 20 2010 |
The installation is successful!
Prepare the Android compiling environment
Download adt-bundle-linux-x86_64-20130729.zip or the latest version in the http://developer.android.com/sdk/index.html and decompress:
The code is as follows: |
Copy code |
Unzip adt-bundle-linux-x86_64-20130729.zip
|
Copy the decompressed sdk directory to/opt/sdk
The code is as follows: |
Copy code |
Cp./adt-bundle-linux-x86_64-20130729/sdk // opt/sdk
|
Set environment variables:
The code is as follows: |
Copy code |
Vim/etc/bash. bashrc
|
Add:
The code is as follows: |
Copy code |
Export ANDROID_SDK_HOME =/opt/sdk/ Export PATH = $ PATH: $ ANDROID_SDK_HOME/tools: $ ANDROID_SDK_HOME/build-tools/android-4.3: $ ANDORID_SDK_HOME/platforms/android-18/
|
Save and run bash to make the environment variable take effect.
Now you can run android to test whether it is successful!
The code is as follows: |
Copy code |
Android create project -- target "android-18" -- name APP -- path App -- activity MainActivity -- package com. yourtion. android
|
JRE is required for compiling and generating APK files. It may need to be installed first. I installed JRE7 files.
The code is as follows: |
Copy code |
Sudo apt-get install openjdk-7-jre openjdk-7-jdk openjdk-7-jre-lib
|
In this way, the environment is basically okay. If you have any questions during usage, please contact us.