Android - use ant to create build configurations that change configuration values

前端 未结 4 1440
春和景丽
春和景丽 2020-12-05 01:19

What I want is a way to have settings that are dependent on build configuration. To give a specific example, my android application connects to a web service. In developme

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 01:51

    As answers mentioned above says, you have to place the URLs in a property file like dev.properties, test.properties, prod.properties etc..

    Now only thing that you need to do is making your build intelligent enough to choose a property file depending upon environment.

    That can be done by passing a parameter to ANT, something like:

    $ ant -file MyBuild.xml -DcurrentEnv=dev (For Development environment)
    $ ant -file MyBuild.xml -DcurrentEnv=test (For Test)
    $ ant -file MyBuild.xml -DcurrentEnv=prod (For Production)

    Inside your build script, this is how you can include your property file:

    
        
    
    

    With this in place, whatever name you supply at the time of build, property file with that name will be picked up.

提交回复
热议问题