как использовать android: apk из simpligility android-maven-плагин

я знаю, что com.jayway.знаток.Плагины.андроид.generation2 groupId также устарел. GroupId плагина теперь com.простота.знаток
.Плагины.i already try jayway ‘ plugin,it’s just ok, when i try simpligility
плагин у меня небольшая проблема.когда я использую цель android: apk, возникает эта ошибка:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenTest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- android-maven-plugin:4.4.1:apk (default-cli) @ MavenTest ---
[INFO] Generating debug apk.
[INFO] D:ToolsEJunoMavenTest2targetAndroidManifest.xml: error: Unable to open file for read: No such file or directory
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.887 s
[INFO] Finished at: 2016-05-29T14:23:28+08:00
[INFO] Final Memory: 22M/362M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.simpligility.maven.plugins:android-maven-plugin:4.4.1:apk (default-cli) on project MavenTest: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "E:JavaEnvironmentAndroid-SDKbuild-tools.0.3aapt.exe package -f -M D:ToolsEJunoMavenTest2targetAndroidManifest.xml --auto-add-overlay -I E:JavaEnvironmentAndroid-SDKplatformsandroid-22android.jar -F D:ToolsEJunoMavenTest2targetMavenTest-0.0.1-SNAPSHOT.ap_ --debug-mode", Result = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

ПФЛ.XML

<project  
    xsi_schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MavenTest</groupId>
    <artifactId>MavenTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
     <build>
        <plugins>
          <plugin>
            <groupId>com.simpligility.maven.plugins</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>4.4.1</version> 
            <extensions>true</extensions>
          </plugin>
        </plugins>
      </build>
</project>

и я копирую AndroidManifest.xml в целевую папку, чтобы попробовать, но проблема exsit.все больше и больше людей используют Android studio, возможно, меньше используют этот способ.я просто хочу упаковать apk с maven.

1 ответ

  1. Вот вам мой рабочий пом.xml он работает для непрерывного развертывания, выпуска, прогуардинга. Адаптация параметров пользователя, пароля и svn, а также параметров proguard (переключение на true или false):

    ПФЛ.XML

    <?xml version="1.0" encoding="UTF-8"?>
    <project   xsi_schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mydomain</groupId>
        <artifactId>myapp</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>apk</packaging>
        <name>MyApp</name>
    
        <scm>
            <connection>scm:svn:https://localhost/svn/myproject</connection>
            <developerConnection>scm:svn:https://localhost/svn/myproject/myapp</developerConnection>
            <url>scm:svn:https://localhost/svn/myrepo</url>
        </scm>
    
        <distributionManagement>
            <repository>
                <id>svnrepo</id>
                <url>svn:https://localhost/svn/myproject/myapp/releases</url>
            </repository>
            <snapshotRepository>
                <id>svnrepo</id>
                <url>svn:https://localhost/svn/myproject/myapp/snapshots</url>
            </snapshotRepository>
        </distributionManagement>
    
        <!-- see also properties in settings.xml! -->
        <properties>
            <android.sdk.path>/opt/android-sdk-linux</android.sdk.path>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.javadoc.skip>true</maven.javadoc.skip>
        </properties>
    
        <dependencies>
            <!-- android 6 -->
            <!-- The dependency was installed by mvn install:install-file -->
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
                <version>6.0</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- Dependencies for AdMob -->
            <dependency>
                <groupId>com.google.android.gms</groupId>
                <artifactId>google-play-services</artifactId>
                <version>26.0.0</version>
                <type>apklib</type>
            </dependency>
    
            <dependency>
                <groupId>com.google.android.gms</groupId>
                <artifactId>google-play-services</artifactId>
                <version>26.0.0</version>
                <type>jar</type>
            </dependency>
    
            <!-- Compatibilty packages: FragmentActivity, NavigationDrawer,... -->
    
            <dependency>
                <groupId>android.support</groupId>
                <artifactId>compatibility-v4</artifactId>
                <version>23.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>android.support</groupId>
                <artifactId>compatibility-v7-appcompat</artifactId>
                <version>23.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>android.support</groupId>
                <artifactId>compatibility-v7-appcompat</artifactId>
                <version>23.0.0</version>
                <type>apklib</type>
            </dependency>
    
            <dependency>
                <groupId>com.android.support</groupId>
                <artifactId>design</artifactId>
                <version>23.0.0</version>
                <type>aar</type>
                <exclusions>
                    <exclusion>
                        <groupId>com.android.support</groupId>
                        <artifactId>appcompat-v7</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.android.support</groupId>
                        <artifactId>support-annotations</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.android.support</groupId>
                        <artifactId>support-v4</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
        </dependencies>
    
        <build>
            <outputDirectory>target/classes</outputDirectory>
            <testOutputDirectory>target/test-classes</testOutputDirectory>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-scm-plugin</artifactId>
                    <version>1.9.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jarsigner-plugin</artifactId>
                    <version>1.2</version>
                    <configuration>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.5</version>
                    <configuration>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>4.0.0-rc.1</version>
                    <extensions>true</extensions>
                    <configuration>
                        <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                        <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                        <resourceDirectory>${project.basedir}/res</resourceDirectory>
                        <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                        <genDirectory>${project.basedir}/gen</genDirectory>
                        <sdk>
                            <platform>23</platform>
                            <path>${android.sdk.path}</path>
                        </sdk>
                        <undeployBeforeDeploy>true</undeployBeforeDeploy>
                        <proguard>
                            <skip>true</skip>
                            <config>proguard.cfg</config>
                        </proguard>
                        <sign>
                            <debug>${debug}</debug>
                        </sign>
                    </configuration>
                </plugin>
            </plugins>
            <pluginManagement>
                <plugins>
                    <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
                    <plugin>
                        <groupId>org.eclipse.m2e</groupId>
                        <artifactId>lifecycle-mapping</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <lifecycleMappingMetadata>
                                <pluginExecutions>
                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                                            <artifactId>android-maven-plugin</artifactId>
                                            <versionRange>4.0.0-rc.1</versionRange>
                                            <goals>
                                                <goal>generate-sources</goal>
                                                <goal>proguard</goal>
                                            </goals>
                                        </pluginExecutionFilter>
                                        <action>
                                            <ignore />
                                        </action>
                                    </pluginExecution>
                                </pluginExecutions>
                            </lifecycleMappingMetadata>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    
        <profiles>
            <profile>
                <id>devel</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <debug>true</debug>
                </properties>
            </profile>
    
            <profile>
                <id>release</id>
                <properties>
                    <debug>false</debug>
                </properties>
                <activation>
                    <property>
                        <name>performRelease</name>
                        <value>true</value>
                    </property>
                </activation>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-release-plugin</artifactId>
                            <version>2.5.1</version>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-deploy-plugin</artifactId>
                            <version>2.8.2</version>
                            <dependencies>
                                <dependency>
                                    <groupId>org.jvnet.wagon-svn</groupId>
                                    <artifactId>wagon-svn</artifactId>
                                    <version>1.12</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jarsigner-plugin</artifactId>
                            <version>1.3.2</version>
                            <executions>
                                <execution>
                                    <id>signing</id>
                                    <goals>
                                        <goal>sign</goal>
                                    </goals>
                                    <phase>package</phase>
                                    <inherited>true</inherited>
                                    <configuration>
                                        <archiveDirectory />
                                        <includes>
                                            <include>target/${project.artifactId}-${project.version}.apk</include>
                                        </includes>
                                        <keystore>${android.keystore}</keystore>
                                        <storepass>${key.password}</storepass>
                                        <keypass>${key.password}</keypass>
                                        <alias>${key.alias}</alias>
                                        <arguments>
                                            <argument>-verbose</argument>
                                            <argument>-sigalg</argument>
                                            <argument>MD5withRSA</argument>
                                            <argument>-digestalg</argument>
                                            <argument>SHA1</argument>
                                        </arguments>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                            <artifactId>android-maven-plugin</artifactId>
                            <inherited>true</inherited>
                            <configuration>
                                <!-- Since non-release builds are now debuggable by default you NEED TO ensure that the release parameter is set to true in your release build. -->
                                <release>true</release>
                                <zipalign>
                                    <verbose>true</verbose>
                                    <skip>false</skip>
                                    <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
                                    <outputApk>${project.build.directory}/${project.artifactId}-${project.version}-RELEASE.apk</outputApk>
                                </zipalign>
    
                            </configuration>
                            <executions>
                                <execution>
                                    <id>zipalign</id>
                                    <phase>install</phase>
                                    <goals>
                                        <goal>zipalign</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>
    

    настройки.XML

    <settings  
               
              xsi_schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
      <pluginGroups>
      </pluginGroups>
    
      <proxies>
      </proxies>
    
      <servers>
        <server>
          <id>svnrepo</id>
          <username>myuser</username>
          <password>mypassword</password>
        </server>
      </servers>
    
      <mirrors>
      </mirrors>
    
      <profiles>
        <profile>
            <id>outsorced-project-properties</id>
            <properties>
                <android.keystore>/home/myuser/.android/release.keystore</android.keystore>
                <key.password>mykeystorepassword</key.password>
                <key.alias>androidreleasekey</key.alias>
            </properties>
        </profile>
      </profiles>
    
      <activeProfiles>
        <activeProfile>outsorced-project-properties</activeProfile>
      </activeProfiles>
    
    </settings>
    

    Непрерывные сборки и развертывания на устройстве выполняются:

    clean install android:deploy android:run 
    

    Управление релизами работает с:

    mvn -X release:prepare -Darguments=-Dusername=youruser -Dpassword=yourpassword
    mvn -X release:perform -Darguments=-Dusername=youruser -Dpassword=yourpassword
    

    Для библиотек поддержки Google также необходимо установить https://github.com/simpligility/maven-android-sdk-deployer