Tag: Message ODI code CLU Pat end command Android obfuscation
Plan to write a complete series of articles using ant packaged Android apps. Three articles. The first article specifically describes the process of using ant to pack Android apps. List some of the customization problems and their solutions, the second introduces my understanding of ant packaging ideas and the main concepts and use, the last one describes the APK package generation process. Implementation of the Environment: operating system: Ubuntu 64bit 14.04 Android SDK Build tools:22.0.1 Android SDK tools:24.3.3 ant:1.9.4proguard:5.2.1jdk:1.7 a simple application of the package process here the package flow contains compilation, code obfuscation, apk signature.
For simple Android apps. Just a few simple steps to complete the operation:
1. Build ant compilation required build.xml under Tools in the SDK folder, call Android Update project build, and use the detailed command to see the reference 1. For example: Switch to your project folder Android Update Project--name own project name-P. The dot following the-p parameter indicates that the current folder will generate the ant compilation required build.xml under the project folder and execute Ant debug directly. You can complete the compilation and generate the debug version number of the APK package under the Bin folder. Several questions to note are: (1) Self-generated build.xml generated several Android-related target: the ability to directly input ant to view the Help instructions (2) encounteredbuild failed How to fix: Be able to see the build failed above the log to see where to run, as well as to see which line in the Build.xml is faulted. The build.xml here refers to the sdk/tools/ant under, for example:
[AAPT] Invalid resource directory Name:project folder/bin/res crunchbuild failedsdk/tools/ant/build.xml:649:the following Error occurred while executing this line:build.xml:694:null returned:1
generally seeRes Crunch, it should be the file you are actively compiling in eclipse and the ant build file conflict. Just turn off Eclipse's own initiative to compile. Clean under Project, you can run ant again.
(3) be able to look at Project.Properties and Local.properties2. Add code obfuscationin the project's Project.Properties file, there is a stare explaining how to open code obfuscation#proguard. Config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txtRemove the # number, and at the same time be able toproguard-project.txt Add the configuration you need special handling
After the change, run ant release and you'll see in the output
-obfuscate:[mkdir] Created dir:project folder/bin/proguard[jar] Building jar:project folder/bin/proguard/original.jar[ Proguard] Proguard, version 5.2.1 ...
I can see the Proguard version number I'm using. However, with Ant Debug is no Proguard, because only release version number to be confused, specific reasons may be specifically described in the article. The mapping file is confused under the Bin folder. Note: If Android:debuggable=true is configured in the Androidmanifest.xml of project, then even ant release will not confuse code 3. The signature first needs to be keystore for the APK signature. Detailed build here is not a small talk, simply say in Eclipse Select Project, right-click Android Tools, export Android application have build options The second is to create a new Ant.properties file under the project folder, which configures your signature information such as: Key.store=kestore file path
key.store.password= Password
key.alias.password= Password
key.alias= aliases now run ant release, under the Bin folder you can generate "project name-release.apk". You finally want the release version number of the APK
In this, the simple Androidproject of the ant compilation is packaged, very convenient.
Ii. adding customization 1. Ant compilation that adds so library Android apps will not compile Jniproject by default, it will only process the library files in Libs.
Assuming that you have a compiled so in your libs, the packaged apk appears to perform normally. In a well-configured Jniproject, only the ndk-build of the NDK can be completed so compile. Therefore, simply add the Custom_rules.xml file to the Build.xml folder, such as the following:
<?xml version= "1.0" encoding= "UTF-8"? ><project name= "project name" default= "Help" ><target name= "-pre-compile" > <echo >ndk build.............................</echo> <exec executable= "${ndk.dir}/ Ndk-build "> </exec></target></project>
Add a row in Local.properties under the same folder. Specify your NDK folder ndk.dir=ndk path run ant release again to see if your so library has been generated
Suppose your jniproject exists as a library project, and the method is the same.
Master project relies on your library project to generate Build.xml in library project, and then follow the above method.
2. Call the Hide API to add Android.jar Many project is based on Android native code changes. Or if you want to invoke some of the system's hidden APIs, you'll use a library file that someone else compiled Android.jar, or Framework.jar and so on, and will ask for the loading order before the Android build number you choose.
In the Java build path->libraries of Eclipse, how do you change the loading order of the ant compilation? Or take advantage of the Custom_rules.xml written earlier, such as the following:
<?xml version= "1.0" encoding= "UTF-8"? ><project name= "Hooktest" default= "Help" ><property name= " Project.target.android.jar "value=" ${sdk.dir}/platforms/${target}/android.jar "/><target name="-pre-compile "> <echo >set Project target class path.............................</echo> <path id=" Project.target.class.path "> <pathelement location=" Framework.jar "/> <pathelement location=" $ {Project.target.android.jar} "/> </path> <property name=" My.project.target.class.path "refid= "Project.target.class.path"/> <echo message= "Project.target.class.path:${my.project.target.class.path } "/></target></project>
3. A multi-source folder in Project if you set up more than one source folder in project, the less appropriate way is to copy the other source code folder to the default SRC, and then delete it after compiling. In fact, by the way, look at the file copy and delete, Custom_rules.xml is also established in project in the multi-source code folder, such as the following:
<target name= "-pre-build" > <echo >copy file.............................</echo> < Copy todir= "${source.absolute.dir}" > <fileset dir= "Other source code Folders" > <include name= "**/*.java"/> <include name= "**/*.aidl"/> </fileset> </copy></target><target name= " Src-clean "> <echo >delete file.............................</echo> <delete dir=" ${ source.absolute.dir}/copy of the Source code folder "/></target><target name="-post-build "depends=" Src-clean "></ Target><target name= "-pre-clean" depends= "Src-clean" ></target>
The code above will also run the source code operation to delete the copy when running ant clean. Before compiling, copy the source code. Contains the Aidl file. After the package is finished, delete the copied source code folder.
A source code in project as much as possible in a folder.
Other issues are also like resource references between library project, assuming that using the default R file directly is not a problem, but if you are using build Java build Path->project in Eclipse to join child project, and using the R file to apply the resources, ant packaging will have to continue to toss
End: Here are just a few of the basic and possible solutions to using Ant's packaged Android app, as well as the use and packaging principles of ant to see the article. Can also read the supplementary article.
Reference: 1.android Command Specific Instructions http://developer.android.com/tools/help/android.html2.ant reference manual https://ant.apache.org/manual/ 3.ant packaging APK specific process can read Sdk/tools/ant/build.xml file
Specific explanations for using ant packaged Android app