Create and package a project using the android command line, and package the project using the android command line.
Create an Android project using the command line to view sdk Information
Change the directory to the path of the Android SDK tools.
Run:
Android list targets
This will print the list of available Android platforms that you have downloaded for your SDK. Find the note that you want to compile your application's platform's target id. We recommend that you select the highest possible version. You can still generate your application to support older versions, but set the generation target to the latest version to allow you to optimize the latest devices of your application.
Create a project
Android create project -- target <target_ID> -- name <your_project_name> -- path/to/your/project -- activity <your_activity_name> -- package
Command example
Android create project -- target 42 -- name MyFirstApp -- path F: \ Workspace_Test \ test \ MyFirstApp -- activity MainActivity -- package com. example. myfirstapp
Command description
42 is the sdk id
MyFirstApp is the project name
F: \ Workspace_Test \ test \ MyFirstApp is the project root directory.
MainActivity is the name of the project main Activity (that is, start Activity)
Com. example. myfirstapp is the project package name
Command Line packaging 1. Generate the R. java file and create the gen directory
If the F: \ Workspace_Test \ test \ MyFirstApp directory does not have the gen directory, run
Mkdir F: \ Workspace_Test \ test \ MyFirstApp \ gen
Run the aaptcommand to generate the r.java file and switch it to the aapt.exe root directory.
Cd F: \ AndroidSDK \ android-sdk-windows \ build-tools \ 19.0.0
Generate the R. java File
Aapt.exe package-f-m-J gen-S res-I F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar-M AndroidManifest. xml
Command description
F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar, which corresponds to the previous 42
2. Compile the java file into a class file
If the bin directory does not exist, use mkdir F: \ Workspace_Test \ test \ MyFirstApp \ bin to create the directory.
Javac-encoding UTF-8-target 1.7-bootclasspath F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar-dbin src \ com \ example \ myfirstapp \*. java gen \ com \ example \ myfirstapp \ R. java
Command description
Jdk 1.7
F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar corresponds to the generated R. java File
Src \ com \ example \ myfirstapp is the location of the java File
Gen \ com \ example \ myfirstapp is the location of the R. java File
3. Generate the dex file (use the absolute path) and switch to the dx. bat root directory.
Cd F: \ AndroidSDK \ android-sdk-windows \ build-tools \ 19.0.0
Generate dex File
Dx. bat -- dex -- output = F: \ Workspace_Test \ test \ MyFirstApp \ bin \ classes. dex F: \ Workspace_Test \ test \ MyFirstApp \ bin
Command description
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ classes. dex indicates the location and name of the dex file.
F: \ Workspace_Test \ test \ MyFirstApp \ bin is the location of the bin folder.
4.generate resource package file switch to aapt.exe root directory
Cd F: \ AndroidSDK \ android-sdk-windows \ build-tools \ 19.0.0
Generate resource package file
If there is no assets folder, first create it with mkdir F: \ Workspace_Test \ test \ MyFirstApp \ assets
Aapt.exe package-f-M AndroidManifest. xml-S res-A assets-I F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar-F bin \ resources
Command description
F: \ AndroidSDK \ android-sdk-windows \ platforms \ android-Honeycomb \ android. jar corresponds to the generated R. java File
5. Generate unsigned apk package (apkbuilder. bat has been deprecated)
Set classpath = F: \ AndroidSDK \ android-sdk-windows \ tools \ lib \ sdklib. jar ;.; % CLASSPATH % (set sdklib. jar reference, in the sdk root directory tools \ lib \ sdklib. jar)
Java com. android. sdklib. build. apkBuilderMain F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app.apk-v-u-z F: \ Workspace_Test \ test \ MyFirstApp \ bin \ resources-f: \ Workspace_Test \ test \ MyFirstApp \ bin \ classes. dex-rf F: \ Workspace_Test \ test \ MyFirstApp \ src
Command description
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app.apk: location and name of the generated unsigned APK
You only need to change all F: \ Workspace_Test \ test \ MyFirstApp to the project root directory path.
6. Generate a signature using the signature
Keytool-genkey-alias android. keystore-keyalg RSA-validity 20000-keystore android. keystore (20000 indicates a deadline (days ))
Switch the signed apk to the sdk tools directory
Cd F: \ AndroidSDK \ android-sdk-windows \ tools
Jarsigner-verbose-keystore F: \ Workspace_Test \ test \ keystore \ android. keystore-storepassandroid-signedjar F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed.apk F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app.apk android. keysotre-digestalg SHA1-sigalg MD5withRSA
Command description
Jdk1.6 without-digestalgSHA1-sigalg MD5withRSA
Jdk1.7 must be followed by-digestalgSHA1-sigalg MD5withRSA
F: \ Workspace_Test \ test \ keystore \ android. keystore is the keystore file path.
Keystore password for android
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed.apk indicates the path of the signed APK File
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app.apk is the path of the unsigned APK File
Android. keysotre is the keystore alias
7. alignment (optimize applications)
Zipalign-v 4 F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed.apk F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed_aligned.apk
Command description
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed.apk indicates the path of the signed APK file.
F: \ Workspace_Test \ test \ MyFirstApp \ bin \ app_signed_aligned.apk is the aligned signature APK file path
Document address: Create and package a project using the android command line
PS: The XXXX blog editor is really a bit confusing. If you copy it from word, there will be more spaces and less spaces. It doesn't matter. The problem is that there shouldn't be more problems, shouldn't be missing?
How can I package and reference the android project of the library project using the command line?
Right-click "Export" and select JAR file under java. Isn't that all right ?!
Use java or C # To call the command line to compile, package, and sign the android project.
Android itself supports ant packaging projects, and the SDK comes with a build. xml file.
This file allows you to compile, package, and install the file. It also supports multiple packaging methods, such as debug or release.
Generally, perform the following operations:
First, create an Android project.
After the project is created, you must add ant support to the project to create the corresponding build. xml file.
This file does not need to be created by the user. You only need to execute the following command:
<Sdk>/tools/android update project-p <project>-t <target>
Where:
The sdk is the installation directory of the sdk, and the tools/android under it is the command we want to use.
Project is the project directory.
Target is the android target id used by the project, that is, the android version corresponding to the project.
You can add the tools directory of the sdk to the environment variable ~ /. In the bashrc file, it takes effect after restart. You can use the command directly later.
You can run the following command to view the target and the corresponding id in the current sdk:
Android list targets
After the android update project command is executed, an ant file is generated in the root directory of the project.
There are three main files: build. xml, ant. properties, and local. properties.
If you do not have the ant. properties file, you can manually add it.
The build. xml file is the main file for ant build. It references other files.
The sdk. dir attribute is defined in the local. properties file, that is, the Directory of the currently used sdk.
In the ant. properties file, you can define some of your own attributes or re-define some attributes.
Of course, these two Property Files are dispensable and it does not matter if they are directly defined in build. xml.
At the end of build. xml, the tools/ant/build. xml file under the sdk directory is referenced.
This is the default build file of the sdk. You can copy the content directly or maintain the current reference method.
By default, build. xml in the project executes help as the target. After running, you can view the help information.
The help information shows other available targets.
Generally, we need to change it to debug or release.
After modification, run the build. xml file to execute the compilation process we need.
To Run the build. xml file, right-click the file and choose Run As> Ant Build.
If the debug version is used, the debug signature is used by default.
For release, you must specify the corresponding keystore and private key.
Otherwise, only one unsigned apk file can be generated.
To set the private key library, add the following content to the ant. properties file:
Key. store = <keystore>
Key. alias = <key>
Key. store. password = <keystore pwd>
Key. alias. password = <key pwd>
Where:
The keystore is a private key library file.
The key is the private key required for signature.
Key. store. password is the password of the private key library.
Key. alias. password is the password of the private key.
You can add only the private key Library and the private key without adding the attributes related to the two passwords.
In this way, the corresponding input boxes will pop up in sequence, prompting the user to enter the corresponding password.
... The remaining full text>