我在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 Revision Number Plugin将修订号放到文件中?
答案 0 :(得分:1)
我找到了解决方案! 从文件中读取subversion我更新了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));
最后工作:)