Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Ant command-line compiler Android project     - CentOS6 5 source compiler installation Hadoop2.5.1 (Server)

- Ceph distributed storage system is installed on a CentOS 7.1 (Server)

- [Android] Eclipse does not update the Android SDK Manager solution [using GoAgent] (Programming)

- Iptables application layer plug (Linux)

- Fundamentals of the Java virtual machine memory management principles (Programming)

- Workaround CentOS error message during compilation PHP5 common (Linux)

- GEC2440 easiest a kernel compile Linux2.6.30.4 (Programming)

- Linux, MySQL / MariaDB Galera Cluster Setup Process (Database)

- Process monitoring tools Supervisor start MongoDB (Database)

- Linux top command to get started (Linux)

- Oracle Data File Management (Database)

- CentOS 6.5 upgrade to CentOS 7 (Linux)

- Spring Data MongoDB combat (Database)

- OpenGL shadow map (Programming)

- Redhat 7 modify the default run level method --RHEL7 use systemd to create a symbolic link to the default runlevel (Linux)

- Android source code compiled fatal error solutions (Programming)

- Linux System Getting Started Learning: install software packages on Ubuntu and Fedora (Linux)

- Linux system performance and usage activity monitoring tools -Sysstat (Linux)

- Composition and dynamic memory allocation C program (Programming)

- Linux Command - ps: a snapshot of the current process (Linux)

 
         
  Ant command-line compiler Android project
     
  Add Date : 2018-11-21      
         
         
         
  First, the tools catalog under Android sdk added to the system path environment variable, or you have to directly specify the absolute path android.bat

For a new project, you can use this command to create the required ant build environment (see android default project file structure)

android create project -k com.foo -a Test1 -t android-8 -p d: \ temp

If it is an existing project, the main project and subprojects run

Project Directory> android update project -s -p. -t Android-19

-s is because the tape project

-t is specified target version, the version does not cause the compiler to fail

among them

build.xml ant task file is the basic need to modify

custom_rules.xml for compilation task requires self-configuring, wrote this document, will be loaded build.xml

ant.properties ant run variables involved wrote here

local.properties which set the path sdk.dir without modification

project.properties set a target to compile and project type, if there is sub, then there subprojects path without modification

Then execute the following command to compile the

Project directory> D: \ apache-ant-1.8.4 \ bin \ ant.bat clean
Project directory> D: \ apache-ant-1.8.4 \ bin \ ant.bat release

According to the newspaper the wrong way, make adjustments

If the sub-compilation errors, you can run ant clean ant release and in the sub-directory, respectively, and to exclude errors

Two similar examples custom_rules.xml

 

< ? Xml version = "1.0" encoding = "UTF-8"?>
< Project name = "custom_rules">
    
    < Property name = "generated.dir" value = "gen" />
    < Property name = "generated.absolute.dir" location = "$ {generated.dir}" />
    < Property name = "java.compilerargs" value = "- s & apos; $ {generated.absolute.dir} & apos;" />
    
    < Target name = "- pre-compile">
        < Mkdir dir = "$ {generated.absolute.dir}" />
    < / Target>
     

    < Target name = "- compile" depends = "- build-setup, -pre-build, -code-gen, -pre-compile">
        < Do-only-if-manifest-hasCode elseText = "hasCode = false. Skipping ...">
            < -! Merge the project's own classpath and the tested project's classpath ->
            < Path id = "project.javac.classpath">
                < Path refid = "project.all.jars.path" />
                < Path refid = "tested.project.classpath" />
                < Fileset dir = "compile-libs" includes = "*. Jar" />
            < / Path>
            < Javac encoding = "$ {java.encoding}"
                  source = "$ {java.source}" target = "$ {java.target}"
                  debug = "true" extdirs = "" includeantruntime = "false"
                  destdir = "$ {out.classes.absolute.dir}"
                  bootclasspathref = "project.target.class.path"
                  verbose = "$ {verbose}"
                  classpathref = "project.javac.classpath"
                  fork = "$ {need.javac.fork}">
                < Src path = "$ {source.absolute.dir}" />
                < Src path = "$ {gen.absolute.dir}" />
                < Compilerarg line = "$ {java.compilerargs}" />
            < / Javac>

            < -! If the project is instrumented, intrument the classes ->
            < If condition = "$ {build.is.instrumented}">
                < Then>
                    < Echo level = "info"> Instrumenting classes from $ {out.absolute.dir} / classes ... < / echo>

                    < -! Build the filter to remove R, Manifest, BuildConfig ->
                    < Getemmafilter
                            appPackage = "$ {project.app.package}"
                            libraryPackagesRefId = "project.library.packages"
                            filterOut = "emma.default.filter" />

                    < -!. Define where the .em file is going This may have been
                        setup already if this is a library ->
                    < Property name = "emma.coverage.absolute.file" location = "$ {out.absolute.dir} /coverage.em" />

                    < -! It only instruments class files, not any external libs ->
                    < Emma enabled = "true">
                        < Instr verbosity = "$ {verbosity}"
                              mode = "overwrite"
                              instrpath = "$ {out.absolute.dir} / classes"
                              outdir = "$ {out.absolute.dir} / classes"
                              metadatafile = "$ {emma.coverage.absolute.file}">
                            < Filter excludes = "$ {emma.default.filter}" />
                            < Filter value = "$ {emma.filter}" />
                        < / Instr>
                    < / Emma>
                < / Then>
            < / If>

            < -! If the project is a library then we generate a jar file ->
            < If condition = "$ {project.is.library}">
                < Then>
                    < Echo level = "info"> Creating library output jar file ... < / echo>
                    < Property name = "out.library.jar.file" location = "$ {out.absolute.dir} /classes.jar" />
                    < If>
                        < Condition>
                            < Length string = "$ {android.package.excludes}" trim = "true" when = "greater" length = "0" />
                        < / Condition>
                        < Then>
                            < Echo level = "info"> Custom jar packaging exclusion: $ {android.package.excludes} < / echo>
                        < / Then>
                    < / If>

                    < Propertybyreplace name = "project.app.package.path" input = "$ {project.app.package}" replace = "." With = "/" />

                    < Jar destfile = "$ {out.library.jar.file}">
                        < Fileset dir = "$ {out.classes.absolute.dir}"
                                includes = "** / *. class"
                                excludes = "$ {project.app.package.path} /R.class $ {project.app.package.path} / R $ *. class $ {project.app.package.path} /BuildConfig.class" />
                        < Fileset dir = "$ {source.absolute.dir}" excludes = "** / *. Java $ {android.package.excludes}" />
                    < / Jar>
                < / Then>
            < / If>

        < / Do-only-if-manifest-hasCode>
    < / Target>
    
< / Project>

 

another

 

< ? Xml version = "1.0" encoding = "UTF-8"?>
< Project name = "app_project" default = "help">
    < Property name = "generated.dir" value = ". Apt_generated" />
    < Property name = "generated.absolute.dir" location = "$ {generated.dir}" />
    < Property name = "java.compilerargs" value = "- s & apos; $ {generated.absolute.dir} & apos;" />

    < Target name = "- pre-compile">
        < Mkdir dir = "$ {generated.absolute.dir}" />
    < / Target>

    < -! Compiles this project's .java files into .class files -.>
    < Target name = "- compile" depends = "- pre-build, -build-setup, -code-gen, -pre-compile">
        < Do-only-if-manifest-hasCode elseText = "hasCode = false. Skipping ...">
            < -! Merge the project's own classpath and the tested project's classpath ->
            < Path id = "project.javac.classpath">
                < Path refid = "project.all.jars.path" />
                < Path refid = "tested.project.classpath" />
                < Path path = "$ {java.compiler.classpath}" />
                < Fileset dir = "compile-libs" includes = "*. Jar" />
            < / Path>
            < Javac encoding = "$ {java.encoding}"
                source = "$ {java.source}" target = "$ {java.target}"
                debug = "true" extdirs = "" includeantruntime = "false"
                destdir = "$ {out.classes.absolute.dir}"
                bootclasspathref = "project.target.class.path"
                verbose = "$ {verbose}"
                classpathref = "project.javac.classpath"
                fork = "$ {need.javac.fork}">
                < Src path = "$ {source.absolute.dir}" />
                < Src path = "$ {gen.absolute.dir}" />
                < Compilerarg line = "$ {java.compilerargs}" />
            < / Javac>

            < -! If the project is instrumented, intrument the classes ->
            < If condition = "$ {build.is.instrumented}">
                < Then>
                    < Echo level = "info"> Instrumenting classes from $ {out.absolute.dir} / classes ... < / echo>
                    
                    < -! Build the filter to remove R, Manifest, BuildConfig ->
                    < Getemmafilter
                        appPackage = "$ {project.app.package}"
                        libraryPackagesRefId = "project.library.packages"
                        filterOut = "emma.default.filter" />

                    < -!. Define where the .em file is going This may have been setup already if this is a library ->
                    < Property name = "emma.coverage.absolute.file" location = "$ {out.absolute.dir} /coverage.em" />
                    
                    < -! It only instruments class files, not any external libs ->
                    < Emma enabled = "true">
                        < Instr verbosity = "$ {verbosity}"
                            mode = "overwrite"
                            instrpath = "$ {out.absolute.dir} / classes"
                            outdir = "$ {out.absolute.dir} / classes"
                            metadatafile = "$ {emma.coverage.absolute.file}">
                            < Filter excludes = "$ {emma.default.filter}" />
                            < Filter value = "$ {emma.filter}" />
                        < / Instr>
                    < / Emma>
                < / Then>
            < / If>

            < -! If the project is a library then we generate a jar file ->
            < If condition = "$ {project.is.library}">
                < Then>
                    < Echo level = "info"> Creating library output jar file ... < / echo>
                    < Property name = "out.library.jar.file" location = "$ {out.absolute.dir} /classes.jar" />
                    < If>
                        < Condition>
                            < Length string = "$ {android.package.excludes}" trim = "true" when = "greater" length = "0" />
                        < / Condition>
                        < Then>
                            < Echo level = "info"> Custom jar packaging exclusion: $ {android.package.excludes} < / echo>
                        < / Then>
                    < / If>

                    < Propertybyreplace name = "project.app.package.path" input = "$ {project.app.package}" replace = "." With = "/" />

                    < Jar destfile = "$ {out.library.jar.file}">
                        < Fileset dir = "$ {out.classes.absolute.dir}"
                            includes = "** / *. class"
                            excludes = "$ {project.app.package.path} /R.class $ {project.app.package.path} / R $ *. class $ {project.app.package.path} /BuildConfig.class" />
                        < Fileset dir = "$ {source.absolute.dir}" excludes = "** / *. Java $ {android.package.excludes}" />
                    < / Jar>
                < / Then>
            < / If>

        < / Do-only-if-manifest-hasCode>
    < / Target>
< / Project>

 

Examples of ant.properties, and above is the corresponding xml

 

key.store = D: /workAndroid/files/android_key.store
key.alias = alia
key.store.password = 111111
key.alias.password = 111111
java.encoding = UTF-8
java.target = 7
java.source = 7

 

 

Use the version number in the generated apk file name, rather than using the default xxx-release.apk

http://jeffreysambells.com/2013/02/14/build-your-android-apk-with-the-manifest-version-number

 

    < Target name = "- set-release-mode"
        depends = "rename-release-with-version-number, android_rules.-set-release-mode">
        < Echo message = "target: $ {build.target}"> < / echo>
    < / Target>

    < Target name = "rename-release-with-version-number">
        < Xmlproperty file = "AndroidManifest.xml" prefix = "themanifest" collapseAttributes = "true" />
        < -! See $ {sdk.dir} /tools/ant/build.xml -set-release-mode ->
        < Property name = "out.packaged.file"
            location = "$ {out.absolute.dir} / $ {ant.project.name} - $ {themanifest.manifest.android:versionName}-release-unsigned.apk" />
        < Property name = "out.final.file"
            location = "$ {out.absolute.dir} / $ {ant.project.name} - $ {themanifest.manifest.android:versionName}-release.apk" />
    < / Target>

 

 

The -set-release-mode target overrides the same target in $ {sdk.dir} /tools/ant/build.xml where the out.final.file file name is originally defined. To add the version number, I override -set -release-mode by calling my rename-release-with-version-number target in the dependencies and then calling the original android_rules.-set-release-mode to finish any other setup there.

The rename-release-with-version-number target simply reads in the manifest and adds the version number to both out.final.file and out.packaged.file.

Now the build APK is ProjectName-version-release.apk and it's automatically used by the rest of the ant build process without clumsy file renaming.
     
         
         
         
  More:      
 
- Specifies the open ports of the SUSE firewall settings (Linux)
- Linux fast set ip bond (Linux)
- Build RubyMine + Ruby On Rails + MySQL development environment under Windows (Server)
- Actual custom yum repository ---- gem commands commonly used parameters (Linux)
- Running the open-source Swift under Linux platform (Linux)
- CentOS 7.0 Enable iptables firewall (Linux)
- Introduction and use of the Raspberry Pi (Linux)
- Modify grub solve computer startup error: ERROR 17 (Linux)
- Analysis of memory mapping process in Linux x86-32 mode (Linux)
- Java application server WildFly (Server)
- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)
- To record command input under Linux (Linux)
- Linux tar compressed exclude a folder (Linux)
- Go build the locale under Windows (Linux)
- Install Firefox 28 on Ubuntu, Linux Mint (Linux)
- Under Ubuntu 15.04 installation JDK8 (Linux)
- Installation JDK1.7 under Ubuntu14.04 64-bit (Linux)
- Python common data type summary (Programming)
- VirtualBox virtual machine to install Linux (Linux)
- How to install Git client in Ubuntu (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.