2012-08-16 49 views
0

我在我的Android應用程序中添加svn修訂版號時遇到問題。 我在谷歌做了一個研究,我發現這個:http://ballardhack.wordpress.com/2010/09/28/subversion-revision-in-android-app-version-with-eclipse/ 但我不想在Eclipse中構建這個項目。 我編譯項目由 'MVN乾淨安裝Android:部署'Android項目中的Subversion號碼

我發現也是這個:http://maven-svn-revision-number-plugin.googlecode.com/svn/site/examples/resource_filtering.html

我把文件 '在/ RES 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全新安裝),我打開文件「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版本號插件到文件?

+1

多少revision.txt文件在最後的apk你做了之後'mvn乾淨安裝'?根目錄下的應該有svn值過濾。 – yorkw 2012-08-16 22:07:54

+0

好的,它的工作。我做了蠢事。我檢查項目中的文件revision.txt不在.apk文件中:] 現在我必須在代碼中讀取此文件,問題將得到解決! :) – plancys 2012-08-17 07:51:45

回答

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

最後工作:)