plancys
plancys

Reputation: 3923

Subversion number in Android project

I have a problem with adding svn revision number in my Android application. I did a research in google and I found this: http://ballardhack.wordpress.com/2010/09/28/subversion-revision-in-android-app-version-with-eclipse/ but i don't want to build this project in Eclipse. I compile project by 'mvn clean install android:deploy'

I found also this: http://maven-svn-revision-number-plugin.googlecode.com/svn/site/examples/resource_filtering.html

I make file 'revision.txt in /res/raw' and add in pom.xml this:

<build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>

        <resources>
            <resource>
                <directory>res/raw/</directory>
                <filtering>true</filtering>
            </resource>
        </resources>


        <plugins>
           <plugin>
                <groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
                <artifactId>svn-revision-number-maven-plugin</artifactId>
                <version>1.13</version> <!-- please use the latest version -->
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <entries>
                        <entry>
                            <prefix>prefix</prefix>
                        </entry>
                    </entries>
                </configuration>
            </plugin>

but it doesn't work! after build (mvn clean install) I open file 'revision.txt' and i have this:

repository = ${prefix.repository}
path = ${prefix.path}
revision = ${prefix.revision}
mixedRevisions = ${prefix.mixedRevisions}
committedRevision = ${prefix.committedRevision}
committedDate = ${prefix.committedDate}
status = ${prefix.status}
specialStatus = ${prefix.specialStatus}

how to put revision number to file with Maven SVN Revision Number Plugin ?

Upvotes: 0

Views: 1114

Answers (1)

plancys
plancys

Reputation: 3923

I found solution! Insted reading subversion from file I update AndroidManifest.xml.

in pom.xml I add:

<plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>update-manifest</id>
                        <goals>
                          <goal>manifest-update</goal>
                        </goals>
                        <configuration>
                          <manifest>
                            <versionName></versionName>
                            <versionCode>${prefix.revision}</versionCode>
                            </manifest>
                            </configuration>
                      </execution>
                </executions>

            </plugin>

in java code:

int version = 0;
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
            version = pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("TAG", "Version number not found in package", e);
        }

        String version_name = "??";
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
            version_name = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("TAG", "Version name not found in package", e);
        }
        TextView tv_version = (TextView)findViewById(R.id.version);
        tv_version.setText("Version: "+ version_name + "." + String.valueOf(version));

And finally works :)

Upvotes: 1

Related Questions