Maven and android - Slightly different builds for different environments

后端 未结 1 1748
旧时难觅i
旧时难觅i 2020-12-10 20:12

Ok I am switching from ant to maven on an android project and wondering if it the following would be easy to implement:

Currently I have a custom build.xml script wh

1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 20:30

    In Maven, this is called resource filtering, android-maven-plugin support filtering the following resource types:

    • AndroidManifest.xml, see this answer.
    • assets/, see this answer.
    • res/, see below.

    Sample res/value/config.xml:

    
    
      ${config.server.url}
    
    

    Sample pom configuration for filtering all xml file under res/ directory:

    
      
        
          ${project.basedir}/res
          true
          ${project.build.directory}/filtered-res
          
            **/*.xml
          
        
      
      
        
          maven-resources-plugin
          
            
              initialize
              
                resources
              
            
          
        
        
          com.jayway.maven.plugins.android.generation2
          android-maven-plugin
          true
          
            
              10
            
            true
            ${project.build.directory}/filtered-res
          
        
      
    
    

    There are several ways to define the substituted value, you can define them in an external properties file with properties-maven-plugin. For simplicity, I prefer to use Maven profiles and define them in pom.xml, like so:

    
      
        dev
        
          dev.company.com
        
      
      
        Test
        
          test.company.com
        
      
      
        Prod
        
          prod.company.com
        
      
    
    

    Then use mvn clean install -Pxxx to build corresponding apk.

    0 讨论(0)
提交回复
热议问题