androidmavenpom.xmlauto-build

maven: apk packed wrong


I tried to compile my project with maven. Here's project structure:

 Root
 |---- app
 |---- test

test - robotium test project.

Here's root pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.tecomgroup</groupId>
        <artifactId>agregator</artifactId>
        <version>6.8.0.1</version>
        <packaging>pom</packaging>
        <name>HandiFox agregator</name>

        <profiles>
            <profile>
                <id>release</id>
                <activation>
                    <property>
                        <name>performRelease</name>
                        <value>true</value>
                    </property>
                </activation>
            </profile>
            <profile>
                <id>sign</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jarsigner-plugin</artifactId>
                            <version>1.2</version>
                            <executions>
                                <execution>
                                    <id>signing</id>
                                    <goals>
                                        <goal>sign</goal>
                                    </goals>
                                    <phase>package</phase>
                                    <inherited>true</inherited>
                                    <configuration>
                                        <archiveDirectory></archiveDirectory>
                                        <includes>
                                            <include>**/*.apk</include>
                                        </includes>
                                        <keystore>C:/ForAndroid/keystore</keystore>
                                        <storepass>2id83kd0e</storepass>
                                        <keypass>8dfjvodw3</keypass>
                                        <alias>handifoxkeystore</alias>
                                        <arguments>
                                            <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>
                                <sign>
                                    <debug>false</debug>
                                </sign>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>

        <modules>
            <module>app</module>
            <module>test</module>
        </modules>

        <url>http://code.google.com/p/maven-android-plugin</url>
        <properties>
            <app_folder>${basedir}</app_folder>
        </properties>

        <build>
            <pluginManagement>
                <plugins>


                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <version>3.6.1</version>
                        <configuration>
                            <manifest>
                                <versionName>${project.version.name}</versionName>
                                <versionCode>${project.version.code}</versionCode>
                                <debuggable>${project.debug.mode}</debuggable>
                            </manifest>
                            <undeployBeforeDeploy>true</undeployBeforeDeploy>
                            <zipalign>
                                <skip>false</skip>
                                <verbose>${project.verbosity}</verbose>
                                <outputApk>${project.build.directory}/${project.build.finalName}-signed-aligned.apk</outputApk>
                            </zipalign>
                        </configuration>
                        <executions>
                                <execution>
                                    <id>zipalign</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>zipalign</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>update-manifest</id>
                                    <goals>
                                        <goal>manifest-update</goal>
                                    </goals>
                                </execution>
                        </executions>

                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <!--
                          During release:perform, enable the "release" profile
                         -->
                        <releaseProfiles>release</releaseProfiles>
                        <goals>deploy assembly:single</goals>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifestEntries>
                                <Build-Source-Version>1.6</Build-Source-Version>
                                <Build-Target-Version>1.6</Build-Target-Version>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>enforce-maven</id>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <requireMavenVersion>
                                        <version>[${maven.version},)</version>
                                        <message>Check for Maven version &gt;=${maven.version} failed. Update your Maven install.</message>
                                    </requireMavenVersion>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    </project>

app pom file:

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
         <parent>
            <groupId>com.tecomgroup</groupId>
            <artifactId>agregator</artifactId>
            <version>6.8.0.1</version>
        </parent>
     <groupId>com.tecomgroup</groupId>
     <artifactId>handifox</artifactId>
     <version>6.8.0.1</version>
     <packaging>apk</packaging>
     <name>HandiFox</name>

       <properties>
        <app_folder>${basedir}</app_folder>
         <project.version.name.number>${version}</project.version.name.number>
         <project.version.code>1</project.version.code>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.version.name>${project.version.name.number}</project.version.name>
         <project.verbosity>true</project.verbosity>
      </properties>

     <dependencies>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
                <version>2.3.3</version>
                <scope>provided</scope>
            </dependency>
             <dependency>
                 <groupId>com.ianywhere</groupId>
                 <artifactId>ultralitejni12</artifactId>
                 <version>1.6</version>
                 <scope>provided</scope>
             </dependency>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>annotations</artifactId>
                <version>4.1.1.4</version>
            </dependency>
     </dependencies>


     <build>
        <finalName>handifox</finalName>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>${project.basedir}/assets</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>

        </resources>

    <pluginManagement>
        <plugins>
            <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <configuration>
                        <encoding>Cp1252</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <sdk>
                            <platform>15</platform>
                        </sdk>
                        <androidManifestFile>${app_folder}/AndroidManifest.xml</androidManifestFile>
                        <sign>     
                            <debug>false</debug>                    
                        </sign>
                    </configuration>
                    <extensions>true</extensions>
                </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <id>install-library</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                          <file>${app_folder}/libs/ultralitejni12.jar</file>
                          <groupId>com.ianywhere</groupId>
                          <artifactId>ultralitejni12</artifactId>
                          <version>1.6</version>
                          <packaging>jar</packaging>
                          <generatePom>true</generatePom>
                        </configuration>
                    </execution>
                </executions>
              </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jarsigner-plugin</artifactId>
                            <version>1.2</version>
                            <executions>
                                <execution>
                                    <id>signing</id>
                                    <goals>
                                        <goal>sign</goal>
                                    </goals>
                                    <inherited>true</inherited>
                                    <configuration>

                                        <includes>
                                            <include>${app_folder}/*.apk</include>
                                        </includes>
                                        <keystore>C:/ForAndroid/keystore</keystore>
                                        <storepass>2id83kd0e</storepass>
                                        <keypass>8dfjvodw3</keypass>
                                        <alias>handifoxkeystore</alias>
                                        <removeExistingSignatures>false</removeExistingSignatures>
                                        <verbose>true</verbose>
                                        <arguments>
                                            <argument>-sigalg</argument><argument>MD5withRSA</argument>
                                            <argument>-digestalg</argument><argument>SHA1</argument>
                                        </arguments>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>



     </plugins>
      </pluginManagement>
      <plugins>
       <plugin>
        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
         <sdk>
          <platform>17</platform>
         </sdk>
        </configuration>
       </plugin>
      </plugins>
     </build>
    </project> 

and test pom file:

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
     http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.tecomgroup</groupId>
            <artifactId>agregator</artifactId>
            <version>6.8.0.1</version>
        </parent>
        <groupId>com.tecomgroup</groupId>
        <artifactId>handifoxtest</artifactId>
        <version>6.8.0.1</version>
        <packaging>apk</packaging>
        <name>HandiFoxTest</name>

        <properties>
            <app_folder>${basedir}</app_folder>
        </properties>

        <dependencies>
            .............
            <!-- andoroid-test -->
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android-test</artifactId>
                <version>2.2.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.tecomgroup</groupId>
                <artifactId>handifox</artifactId>
                <version>6.8.0.1</version>
                <scope>provided</scope>
                <type>apk</type>
            </dependency>
            <dependency>
                <groupId>com.tecomgroup</groupId>
                <artifactId>handifox</artifactId>
                <version>6.8.0.1</version>
                <scope>provided</scope>
                <type>jar</type>
            </dependency>
        </dependencies>


        <build>
            <finalName>handifox-test</finalName>
            <sourceDirectory>src</sourceDirectory>
            <resources>
                <resource>
                    <directory>${project.basedir}/assets</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>**/*.properties</include>
                    </includes>
                </resource>

            </resources>

            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <version>3.6.1</version>
                        <configuration>
                            <sdk>
                                <platform>15</platform>
                            </sdk>
                            <androidManifestFile>${app_folder}/AndroidManifest.xml</androidManifestFile>
                            <sign>
                                <debug>false</debug>
                            </sign>
                        </configuration>
                        <extensions>true</extensions>
                    </plugin>


                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <id>signing</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <inherited>true</inherited>
                                <configuration>

                                    <includes>
                                        <include>${app_folder}/*.apk</include>
                                    </includes>
                                    <keystore>C:/ForAndroid/keystore</keystore>
                                    <storepass>2id83kd0e</storepass>
                                    <keypass>8dfjvodw3</keypass>
                                    <alias>handifoxkeystore</alias>
                                    <removeExistingSignatures>false</removeExistingSignatures>
                                    <verbose>true</verbose>
                                    <arguments>
                                        <argument>-sigalg</argument><argument>MD5withRSA</argument>
                                        <argument>-digestalg</argument><argument>SHA1</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>



                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <sdk>
                            <platform>17</platform>
                        </sdk>
                    </configuration>
                </plugin>
            </plugins>
        </build>


    </project>

I pack it with such command:

mvn package -DperformRelease=true -Psign

It packs apk files without errors. When I install it and then run on the device, there is error:

    08-28 11:49:02.972: W/dalvikvm(18177): VFY: unable to resolve exception class 186 (Lcom/ianywhere/ultralitejni12/ULjException;)
    08-28 11:49:02.972: W/dalvikvm(18177): VFY: unable to find exception handler at addr 0x30
    08-28 11:49:02.972: W/dalvikvm(18177): VFY:  rejected Lcom/tecomgroup/handifox/ApplicationObject;.iniDatabase ()Z
    08-28 11:49:02.972: W/dalvikvm(18177): VFY:  rejecting opcode 0x0d at 0x0030
    08-28 11:49:02.982: W/dalvikvm(18177): VFY:  rejected Lcom/tecomgroup/handifox/ApplicationObject;.iniDatabase ()Z
    08-28 11:49:02.982: I/jdwp(16177): Ignoring second debugger -- accepting and dropping
    08-28 11:49:02.982: I/jdwp(10406): Ignoring second debugger -- accepting and dropping
    08-28 11:49:02.982: W/dalvikvm(18177): Verifier rejected class Lcom/tecomgroup/handifox/ApplicationObject;
    08-28 11:49:02.982: W/dalvikvm(18177): Class init failed in newInstance call (Lcom/tecomgroup/handifox/ApplicationObject;)
    08-28 11:49:02.982: D/AndroidRuntime(18177): Shutting down VM
    08-28 11:49:02.982: W/dalvikvm(18177): threadid=1: thread exiting with uncaught exception (group=0x40b161f8)
    08-28 11:49:03.002: I/jdwp(1622): Ignoring second debugger -- accepting and dropping
    08-28 11:49:03.032: E/AndroidRuntime(18177): FATAL EXCEPTION: main
    08-28 11:49:03.032: E/AndroidRuntime(18177): java.lang.VerifyError: com/tecomgroup/handifox/ApplicationObject
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at java.lang.Class.newInstanceImpl(Native Method)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at java.lang.Class.newInstance(Class.java:1319)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.Instrumentation.newApplication(Instrumentation.java:959)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.Instrumentation.newApplication(Instrumentation.java:944)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.LoadedApk.makeApplication(LoadedApk.java:477)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.ActivityThread.access$1300(ActivityThread.java:123)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.os.Handler.dispatchMessage(Handler.java:99)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.os.Looper.loop(Looper.java:137)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at android.app.ActivityThread.main(ActivityThread.java:4424)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at java.lang.reflect.Method.invoke(Method.java:511)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    08-28 11:49:03.032: E/AndroidRuntime(18177):    at dalvik.system.NativeStart.main(Native Method)
    08-28 11:49:03.062: W/ActivityManager(1456):   Force finishing activity com.tecomgroup.handifox/.LoginWindow
    08-28 11:49:03.142: W/InputManagerService(1456): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41b9fa50
    08-28 11:49:03.352: E/aa(1456): kkk pid=1456
    08-28 11:49:03.352: E/aa(1456): kkk cmdlineString[0]:ystem_server
    08-28 11:49:03.352: E/aa(1456): kkk cmdlineString[1]:null
    08-28 11:49:03.582: W/ActivityManager(1456): Activity pause timeout for ActivityRecord{419f63d0 com.tecomgroup.handifox/.LoginWindow}

Can anybody help with it?


Solution

  • Scope "provided" should be removed (in dependencies), then jar libraries will be merged to apk file, as default scope is "compile".