2

I have tried to use properties file to read properties to set those values into apk while building using maven.

Pluging i have used ->>>>>>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-1</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>${basedir}/buildNumber.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>


<build>
    <sourceDirectory>src</sourceDirectory>
    <finalName>myapk.${majorversion}.${minor_version}.${patch_version}.${maven.build.timestamp}</finalName>

File: buildNumber.properties

major_version=01
minor_version=00
patch_version=00

This generating myapk.01.00.00.20120127-2010.jar but apk is myapk.${major_version}.a.${minor_version}.${patch_version}.20120127-2010.apk

Let me know what I am missing here..?

tumbudu
  • 699
  • 11
  • 26
  • Could you repeat again, what is being generated and what do you expect (two distinct filenames)? I am a bit confused with ".a." which is in your pattern in comment, but in pattern in POM. – dma_k Jan 28 '12 at 12:11
  • OOps... "a" was a typo.. expetcted apk myapk.01.00.00.20120127-2010.apk actual apk is myapk.${major_version}.${minor_version}.${patch_version}.20120127-2010.apk – tumbudu Jan 28 '12 at 18:10
  • Ah, I got it: the placeholders in apk name where not substituted. `` impacts only jar final name, and apk plugin seems not to catch this setting properly. – dma_k Jan 29 '12 at 09:04

1 Answers1

0

I don't know the exact reason, but it looks like properties-maven-plugin can substitute the property value properly defined under properties tag in pom.xml, and maven can only recognize the properties name explicitly defined in pom.xml, the following pom works for me:

<properties>
  <!-- use property name defined in your buildNumber.properties -->
  <external.build.version>${major_version}</external.build.version>
</properties>

... ...

<build>
  <sourceDirectory>src</sourceDirectory>
  <!-- use property name defined earlier in this pom.xml -->
  <finalName>myapk.${external.build.version}</finalName>

... ...

EDIT:
From my point of view, The predefined build lifecycle of maven is quite exclusive especially when integrating with other build tools like ADT, the pom version used for generating the apk is quite restricted, moreover, from the plugin documentation, current version of android-maven-plugin does not provide any configuration for customizing the final apk name during apk goal. A similar discussion was posted here end up with a not so perfect answer.

As a last shot, android-maven-plugin provide options to customize the final apk name during zipalign goal:

<plugin>
  <groupId>com.jayway.maven.plugins.android.generation2</groupId>
  <artifactId>android-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <sdk>
      <platform>13</platform>
    </sdk>
    <undeployBeforeDeploy>true</undeployBeforeDeploy>
    <zipalign>
      <verbose>true</verbose>
      <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
      <!-- directly use property name defined in external properties file here -->
      <outputApk>${project.build.directory}/${project.artifactId}-${major_version}-aligned.apk</outputApk>
    </zipalign>
  </configuration>
  <executions>
    <execution>
      <id>alignApk</id>
      <phase>package</phase>
      <goals>
        <goal>zipalign</goal>
      </goals>
    </execution>
  </executions>
</plugin>

This could be a solution if you use maven zipalign your final apk (I suppose you do), you will get all three output files (.ap_ and .apk and .jar) end with the default ${project.version} plus another apk end with ${major_version}-aligned, however only those three with the default ${project.version} will get installed in the maven central repository.

Community
  • 1
  • 1
yorkw
  • 40,926
  • 10
  • 117
  • 130