Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:04:01+00:00 2026-05-27T18:04:01+00:00

I would like to build two versions of my Android application using an Apache

  • 0

I would like to build two versions of my Androidapplication using an Apache ant file. The problem is, that both versions are identical except the advertisement in the lite version. I read about using Configurations with ant to build debug versions.

The following class defines some constants that can be referenced within the application.

public class Config {
    // Whether or not to include logging in the app.
    public final static boolean LOGGING = true;
}

And here is an example on how to use this constants to determine if logging is enabled or not.

if (Config.LOGGING) {
    Log.d(TAG, "[onCreate] Success");
}

Now i can enable and disable logging in my properties file.

# Turn on or off logging.
config.logging=true

That does not work, because before using this config I have to create a second config file and use filterset and copy.

public class Config {
    // Whether or not to include logging in the app.
    public final static boolean LOGGING = @CONFIG.LOGGING@;
}

That’s pretty easy, but how I could use this to build two versions of my application with and without advertisement. And how could I change the package names using ant, so the android market would accept both packages (Full and Lite).


Thank you, for your suggestions, but I still have some problems.

I managed to write some basic targets that cleanup my builds and copy all files needed to build the application in two folders /full and /lite. So I have two directories with the same content. Now I rename all matches of the applications package name in all *.java files and the AndroidManifest file (target prepare).

To really build two different version I would now have to include the code from my first post. But how do I have to do this and how can I build both versions in the release target and write the resulting *.apk files into the build directoy?

Finally … Would that be all I have to do to build running *.apks that would be accepted by the android market?

<?xml version="1.0" encoding="UTF-8"?>
<project name="my.application" default="help" basedir=".">
    <!-- Load the custom property files -->
    <property file="build.properties" />
    <property file="passwords.properties" />

    <!-- Set global properties for this build -->
    <property name="my.application.pkg" value="my.application"/>
    <property name="my.application.pkg.full" value="my.application.full"/>
    <property name="my.application.pkg.lite" value="my.application.lite"/>

    <property name="my.application" location="."/>
    <property name="my.application.build" location="build"/>
    <property name="my.application.src" location="src"/>
    <property name="my.application.res" location="res"/>
    <property name="my.application.gen" location="gen"/>

    <property name="my.application.full" location="full"/>
    <property name="my.application.full.src" location="full/src"/>
    <property name="my.application.full.res" location="full/res"/>
    <property name="my.application.full.gen" location="full/gen"/>
    <property name="my.application.full.build" location="full/build"/>

    <property name="my.application.lite" location="lite"/>
    <property name="my.application.lite.build" location="lite/build"/>
    <property name="my.application.lite.src" location="lite/src"/>
    <property name="my.application.lite.res" location="lite/res"/>
    <property name="my.application.lite.gen" location="lite/gen"/>

    <!-- Create and update the local.properties file -->
    <loadproperties srcFile="local.properties" />

    <!-- Load the ant.properties file -->
    <property file="ant.properties" />

    <!-- Load the project.properties file -->
    <loadproperties srcFile="project.properties" />

    <!-- Quick check on sdk.dir. -->
    <fail
        message="sdk.dir is missing."
        unless="sdk.dir" />

    <!-- Version-tag: 1 -->
    <import file="${sdk.dir}/tools/ant/build.xml" />

    <target name="release" depends="report, prepare">
        <echo>Building the target!</echo>
    </target>

    <target name="prepare" depends="cleanup" >
        <!-- Copy the Manifest.xml to the full copy -->
        <copyfile src="${my.application}/AndroidManifest.xml" 
            dest="${my.application.full}/AndroidManifest.xml" />

        <!-- Copy the source files to the full copy -->
        <copy todir="${my.application.full.src}" overwrite="true">
            <fileset dir="${my.application.src}" /> 
        </copy>

        <!-- Copy the resources to the full copy -->
        <copy todir="${my.application.full.res}" overwrite="true">
            <fileset dir="${my.application.res}" /> 
        </copy>

        <!-- Copy the generated to the full copy -->
        <copy todir="${my.application.full.gen}" overwrite="true">
            <fileset dir="${my.application.gen}" /> 
        </copy>

        <!-- Replace the package name in the full manifest file -->
        <replaceregexp file="${my.application.full}/AndroidManifest.xml"
            match='package="(.*)"'
            replace='package="${my.application.pkg.full}"'
            byline="false" />

        <!-- Change the package name in all Java files -->
        <replaceregexp flags="g" byline="false">
            <regexp pattern="${my.application.pkg}" /> 
            <substitution expression="${my.application.pkg.full}" />
            <fileset dir="${my.application.full.src}" includes="**/*.java" /> 
        </replaceregexp>

        <!-- Copy the Manifest.xml to the lite copy -->
        <copyfile src="${my.application}/AndroidManifest.xml" 
            dest="${my.application.lite}/AndroidManifest.xml" />

        <!-- Copy the source files to the lite copy -->
        <copy todir="${my.application.lite.src}" overwrite="true">
            <fileset dir="${my.application.src}" /> 
        </copy>

        <!-- Copy the resources to the lite copy -->
        <copy todir="${my.application.lite.res}" overwrite="true">
            <fileset dir="${my.application.res}" /> 
        </copy>

        <!-- Copy the generated to the lite copy -->
        <copy todir="${my.application.lite.gen}" overwrite="true">
            <fileset dir="${my.application.gen}" /> 
        </copy>

        <!-- Replace the package name in the lite manifest file -->
        <replaceregexp file="${my.application.lite}/AndroidManifest.xml"
            match='package="(.*)"'
            replace='package="${my.application.pkg.lite}"'
            byline="false" />

        <!-- Change the package name in all Java files -->
        <replaceregexp flags="g" byline="false">
            <regexp pattern="${my.application.pkg}" /> 
            <substitution expression="${my.application.pkg.lite}" />
            <fileset dir="${my.application.lite.src}" includes="**/*.java" /> 
        </replaceregexp>
    </target>

    <!-- Deletes all directories, not needed anymore after compiling the source files -->
    <target name="cleanup">
        <!-- Delete the full version build dir -->
        <delete dir="${my.application.full}"/>
        <!-- Delete the lite version build dir -->
        <delete dir="${my.application.lite}"/>
        <!-- Delete the *.apk file -->
        <delete file="my.application.full.apk"/>
        <!-- Delete the *.apk file -->
        <delete file="my.application.lite.apk"/>
    </target>
</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:04:02+00:00Added an answer on May 27, 2026 at 6:04 pm

    There are a number of ways in which you could achieve what you require.

    Here are a couple of ideas that I have used in the past,

    1) Have two application ‘heads’ that pull in a common Android library.
    Each head initializes static data that sets up the library to behave as either the lite or the full version of your application.
    This has the advantage that you can perform the build from Eclipse projects as well as with Ant.

    2) Have two seperate build targets that share common build targets to create two seperate apk files.
    In the Ant build script have it build two versions of the APK.
    One that is the full version and then the other which builds the lite version.
    The difference between the two targets are that they build using slightly different files (either by copying, directing to diferent directories or modifying with scripts).

    This can all be done in Ant using targets and properties.

    If at the top level of your build you have a release target depending on two other targets.

    e.g.

    <target name="release"
      depends="release-Full, release-Lite">
    </target>
    
    <target name="release-Full">
      <ant antfile="thisbuild.xml" inheritAll="true" target="full">
        <property name="MyCustomProperty" value="Full" />
      </ant>
    </target>
    
    
    
    <target name="release-Lite">
      <ant antfile="thisbuild.xml" inheritAll="true" target="lite">
        <property name="MyCustomProperty" value="Lite" />
       </ant>
     </target>
    

    You can then use these targets and properties to modify your build to do whatever you require to build each of the APK files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build an application that will run on a web, this
I would like to build a cross-platform GUI application in Python that displays PostScript
I would like to build two different versions of a WAR in Maven (I
I would like to accomplish two things during my build process: Run unit tests
I would like to build a regexp in Java that would be passed in
I would like to build a query that will pull the number of rows
I would like to build an excel VBA program to find all the match
I would like to build some code which calls some code on loadup of
I would like to build a static version of QT Library for X11 like
I would like to build some smaller scale but hightly customized documentation sites for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.