私は自分のプロジェクトで作業し、パッケージ化しているプロファイルに基づいて変更したい属性を更新する Maven の目標 update-manifest を持っています。残念ながら、ソース管理にあるマニフェストが変更されます。パッケージ化されているマニフェストを変更したいのですが、マスター バージョンはそのままにしておきます。target/ の下に、指定できる AndroidManifest のバージョンが表示されません。android-maven プラグイン バージョン 3.2 を使用しています
2 に答える
manifestVersionCodeやmanifestVersionNameなどの構成を使用してマニフェストを更新する場合、これが設計され、動作するはずの方法であり、変更を元の AndroidManifest.xml に書き込みます。
マニフェストを更新するのではなく、フィルターマニフェストが本当に必要なようです。リソース フィルタリングは、android-maven-plugin でサポートされ、頻繁に使用される別の使用シナリオです。
サンプル AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
android:versionCode="${app.version.code}"
android:versionName="${app.version.name}">
... ...
サンプル pom.xml:
<!-- value to be substituted in manifest -->
<properties>
<app.version.code>1</app.version.code>
<app.version.name>1.0.0-SNAPSHOT</app.version.name>
</properties>
... ...
<build>
<resources>
<!-- filter manifest and put filtered file in target/filtered-manifest/ -->
<resource>
<directory>${project.basedir}</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/filtered-manifest</targetPath>
<includes>
<include>AndroidManifest.xml</include>
</includes>
</resource>
</resources>
... ...
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<!-- tell build process to use filtered manifest -->
<androidManifestFile>${project.build.directory}/filtered-manifest/AndroidManifest.xml</androidManifestFile>
</configuration>
</plugin>
... ...
これで、android-maven-plugin はフィルタリングされた AndroidManifest.xml を使用し、元の AndroidManifest.xml は変更されません。
お役に立てれば。
アップデート:
これも必要かもしれません:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
これを達成するには、 maven-android-pluginのmanifest-updateゴールを使用することをお勧めします。
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<!-- This is for maven update properties in AndroidManifest file. Working outside eclipse. -->
<executions>
<execution>
<id>update-manifest</id>
<phase>process-resources</phase>
<goals>
<goal>manifest-update</goal>
</goals>
<configuration>
<manifest>
<versionCode>${project.codeVersion}</versionCode>
<versionName>${project.version}</versionName>
</manifest>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
以下も定義する必要がありますproject.codeVersion
。
<properties>
<project.codeVersion>1</project.codeVersion>
</properties>
Maven は AndroidManifest.xml を更新します。
[INFO] --- android-maven-plugin:3.3.2:manifest-update (update-manifest) @ myapp --- [INFO] Attempting to update manifest d:\dsv\project\MyApp\AndroidManifest.xml [INFO] Setting android:versionName to 0.0.4 [INFO] Setting android:versionCode to 1 [INFO] Made changes to manifest file, updating d:\...\MyApp\AndroidManifest.xml
android:manifest-updateゴールの詳細については、こちらを参照してください。便利なパラメーターがいくつかあります。
重要な注意:このソリューションはコマンド ラインからのみ機能し、プラグインの実行は m2e-android ではまだサポートされていません (この問題を参照してください)。