0

我在我的 Android 应用程序中添加 svn 修订号时遇到问题。我在谷歌做了一项研究,我发现了这个:http ://ballardhack.wordpress.com/2010/09/28/subversion-revision-in-android-app-version-with-eclipse/ 但我不想在 Eclipse 中构建这个项目。我通过 'mvn clean install android:deploy' 编译项目

我还发现了这个: http: //maven-svn-revision-number-plugin.googlecode.com/svn/site/examples/resource_filtering.html

我在 /res/raw 中创建文件“revision.txt”并在 pom.xml 中添加:

<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>

但它不起作用!构建后(mvn clean install)我打开文件'revision.txt',我有这个:

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

如何使用 Maven SVN 修订号插件将修订号归档?

4

1 回答 1

1

我找到了解决方案!Insted 从文件中读取颠覆,我更新了 AndroidManifest.xml。

在 pom.xml 我添加:

<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>

在java代码中:

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));

最后工作:)

于 2012-08-17T13:56:25.017 回答