Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Ant command-line compiler Android project     - RHEL 5.7 Yum configure local source [Errno 2] No such file or directory (Linux)

- Linux disk and File System Concepts (Linux)

- Protect your files, modify the Linux value Umask (Linux)

- Use Mop monitor stock prices at the Linux command line (Linux)

- [SHELL] MySQL primary recovery solution from + Keepalived online (Server)

- Oracle 11g users to create, authorize and import dmp file (Database)

- RMAN backup file is much larger than the size of the database Cause Analysis (Database)

- Install Oracle database error process of [INS-35172] (Database)

- Systemd on RHEL7 (Linux)

- Partition contrast manifestations under Windows and Linux (Linux)

- Linux, grep, sed usage (Linux)

- In Debian 4.3 compiler under Linux-2.6.28 kernel Summary (Programming)

- Installation of Ubuntu Make under Ubuntu 15.10 (Linux)

- Mac OS X system setup Google Go language development environment configuration tool Sublime Text 2 (Linux)

- Ceph cluster disk is no workaround for the remaining space (Server)

- CentOS iptables firewall configuration (Linux)

- How to manage start-up applications in Ubuntu (Linux)

- apt-get install openstack pkg Troubleshooting (Linux)

- Installation Mate Desktop in FreeBSD 10.1 (Linux)

- Linux Network Programming - non-blocking program (Programming)

 
         
  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:      
 
- Linux package manager - yum (Linux)
- Hadoop configuration ssh automation of automation (Server)
- Linux Security Module (LSM) Introduction (Linux)
- To install Scribus 1.4.4 under ubuntu (Linux)
- Nginx Performance Tuning Guidelines (Server)
- gzip, bzip2, xz, tar, zip compression, archive Detailed (Linux)
- Linux ldconfig command (Linux)
- Install FFmpeg compiling from source in Mac OS X environment (Linux)
- Depth Java Singleton (Programming)
- installation process of Matlab 2012a under Ubuntu 14.04 (Linux)
- Apache2.4.7 make an error [exports.lo] Error 1 Solution (Server)
- When RHEL7 use fdisk partition, all partitions can not be used (Linux)
- Tomcat configuration memory and remote debug port (Server)
- Ubuntu / openSUSE users to install Veusz 1.21.1 (Linux)
- Monitoring Linux System 7 command-line tool (Linux)
- xargs Detailed description (Linux)
- GRUB2 boot Ubuntu Manual (Linux)
- ActiveMQ configuration Getting Started Tutorial (Server)
- Linux security settings Basics (Linux)
- Oracle database on the hit rate of query summary (Database)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.