2012-12-19 53 views
4

這是this question的重複,但該答案無法解決我的問題。APK在使用maven構建時缺少一些類

一些背景,我的具體編譯環境:

我使用Android maven plugin隨着this示例項目。該項目由父母pom.xml,然後pom.xml爲三個子模塊(項目)中的每一個。每個子模塊都將父級定義爲父級。

當我在原始下載項目上運行mvn clean install時,它會在手機上建立並安裝/運行。

但我沒有添加到Eclipse的源代碼,它運行良好,讓mvn構建腳本不再工作(即apk更小並且缺少類)。

關於如何解決這個問題的任何想法將不勝感激。

這裏是POM父文件夾,然後POM爲應用程序項目。 很抱歉發佈了這麼大的代碼塊,但我不確定問題出在哪裏。

更新對於面對我已經開始對谷歌集團[Maven的Android開發者]位於here轉換類似的問題的人。我可能會先在那裏得到答案。

<?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> 
    <groupId>com.simpligility.android.morse</groupId> 
    <artifactId>morseflash-parent</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 
    <name>MorseFlash - Parent</name> 

    <properties> 
     <server_schema>http</server_schema> 
    </properties> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>junit</groupId> 
       <artifactId>junit</artifactId> 
       <version>4.8.1</version> 
      </dependency> 
      <dependency> 
       <groupId>com.google.android</groupId> 
       <artifactId>android</artifactId> 
       <version>2.3.1</version> 
      </dependency> 
      <dependency> 
       <groupId>com.google.android</groupId> 
       <artifactId>android-test</artifactId> 
       <version>2.3.1</version> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <build> 

     <pluginManagement> 
      <plugins> 
       <plugin> 
        <artifactId>maven-jarsigner-plugin</artifactId> 
        <version>1.2</version> 
       </plugin> 
       <plugin> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.5</version> 
        <configuration> 
         <encoding>UTF-8</encoding> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
        <artifactId>android-maven-plugin</artifactId> 
        <version>3.4.1</version> 

        <configuration> 
         <sdk> 
          <platform>10</platform> 
         </sdk> 
         <emulator> 
          <avd>23</avd> 
          <wait>10000</wait> 
          <!--<options>-no-skin</options> --> 
         </emulator> 
         <zipalign> 
          <verbose>true</verbose> 
         </zipalign> 
         <undeployBeforeDeploy>true</undeployBeforeDeploy> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>build-helper-maven-plugin</artifactId> 
        <version>1.5</version> 
       </plugin> 
       <!--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>[3.2.0,)</versionRange> 
             <goals> 
              <goal>manifest-update</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute /> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <profiles> 
     <profile> 
      <!-- the standard profile runs the instrumentation tests --> 
      <id>standard</id> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <modules> 
       <module>morse-lib</module> 
       <module>morseflash-app</module> 
       <module>morseflash-instrumentation</module> 
      </modules> 
      <properties> 
       <!-- when i will try to enter this address the app will start :) --> 
       <!-- for development i want to use my local host --> 
       <!-- server schema is defined globally for all profiles but can be overridden 
        here for the local profile --> 
       <!-- this properties are good for all the maven modules --> 
       <server_host>192.168.1.12</server_host> 
       <server_path></server_path> 
      </properties> 
     </profile> 
     <profile> 
      <!-- the release profile does sign, proguard, zipalign ... but does not 
       run instrumentation tests --> 
      <id>release</id> 
      <!-- via this activation the profile is automatically used when the release 
       is done with the maven release plugin --> 
      <activation> 
       <property> 
        <name>performRelease</name> 
        <value>true</value> 
       </property> 
      </activation> 
      <modules> 
       <module>morse-lib</module> 
       <module>morseflash-app</module> 
      </modules> 
      <properties> 
       <!-- when i will try to enter this address the app will start :) --> 
       <!-- for release i want to use my git --> 
       <!-- server schema is defined globally for all profiles but can be overridden 
        here for the local profile --> 
       <!-- this properties are good for all the maven modules --> 
       <server_host>github.com</server_host> 
       <server_path>/jayway/maven-android-plugin-samples</server_path> 
      </properties> 
     </profile> 
    </profiles> 

</project> 

現在對於應用項目:

<?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.simpligility.android.morse</groupId> 
     <artifactId>morseflash-parent</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>morseflash-app</artifactId> 
    <packaging>apk</packaging> 
    <name>MorseFlash - App</name> 

    <properties> 
     <environment>development</environment> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.simpligility.android.morse</groupId> 
      <artifactId>morse-library</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android-test</artifactId> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 

    <build> 

    <!-- <sourceDirectory>src</sourceDirectory> --> 

    <finalName>${project.artifactId}</finalName> 

     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
       <executions> 
        <execution> 
         <!-- use the copy resources instead of resources, which adds it to 
          the eclipse buildpath --> 
         <phase>initialize</phase> 
         <goals> 
          <goal>copy-resources</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${project.basedir}/res</outputDirectory> 
          <resources> 
           <resource> 
            <directory>${project.basedir}/src/templates/res</directory> 
            <targetPath>${project.basedir}/res</targetPath> 
            <filtering>true</filtering> 
           </resource> 
          </resources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 
       <extensions>true</extensions> 
       <configuration> 
        <manifest> 
         <debuggable>true</debuggable> 
        </manifest> 
       </configuration> 
       <executions> 
        <execution> 
         <id>manifestUpdate</id> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>manifest-update</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>alignApk</id> 
         <phase>package</phase> 
         <goals> 
          <goal>zipalign</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <profiles> 
     <profile> 
      <id>development</id> 
      <!-- using this since activeByDefault does not work well with multiple 
       profiles --> 
      <activation> 
       <property> 
        <name>environment</name> 
        <value>!production</value> 
       </property> 
      </activation> 
      <properties> 
       <deployment.stage>In Development</deployment.stage> 
      </properties> 
     </profile> 
     <profile> 
      <id>production</id> 
      <properties> 
       <deployment.stage>In Production</deployment.stage> 
      </properties> 
     </profile> 
     <profile> 
      <id>release</id> 
      <!-- via this activation the profile is automatically used when the release 
       is done with the maven release plugin --> 
      <activation> 
       <property> 
        <name>performRelease</name> 
        <value>true</value> 
       </property> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-jarsigner-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>signing</id> 
           <goals> 
            <goal>sign</goal> 
            <goal>verify</goal> 
           </goals> 
           <phase>package</phase> 
           <inherited>true</inherited> 
           <configuration> 
            <removeExistingSignatures>true</removeExistingSignatures> 
            <archiveDirectory /> 
            <includes> 
             <include>${project.build.directory}/${project.artifactId}.apk</include> 
            </includes> 
            <keystore>${sign.keystore}</keystore> 
            <alias>${sign.alias}</alias> 
            <storepass>${sign.storepass}</storepass> 
            <keypass>${sign.keypass}</keypass> 
            <verbose>true</verbose> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
        <!-- the signed apk then needs to be zipaligned and we activate proguard 
         and we run the manifest update --> 
        <plugin> 
         <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
         <artifactId>android-maven-plugin</artifactId> 
         <inherited>true</inherited> 
         <configuration> 
          <sign> 
           <debug>false</debug> 
          </sign> 
          <zipalign> 
           <skip>false</skip> 
           <verbose>true</verbose> 
           <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk> 
           <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk 
           </outputApk> 
          </zipalign> 
          <manifest> 
           <debuggable>false</debuggable> 
           <versionCodeAutoIncrement>true</versionCodeAutoIncrement> 
          </manifest> 
          <proguard> 
           <skip>false</skip> 
          </proguard> 
         </configuration> 
         <executions> 
          <execution> 
           <id>manifestUpdate</id> 
           <phase>process-resources</phase> 
           <goals> 
            <goal>manifest-update</goal> 
           </goals> 
          </execution> 
          <execution> 
           <id>alignApk</id> 
           <phase>package</phase> 
           <goals> 
            <goal>zipalign</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>build-helper-maven-plugin</artifactId> 
         <configuration> 
          <artifacts> 
           <artifact> 
            <file>${project.build.directory}/${project.artifactId}-signed-aligned.apk</file> 
            <type>apk</type> 
            <classifier>signed-aligned</classifier> 
           </artifact> 
           <artifact> 
            <file>${project.build.directory}/proguard/mapping.txt</file> 
            <type>map</type> 
            <classifier>release</classifier> 
           </artifact> 
          </artifacts> 
         </configuration> 
         <executions> 
          <execution> 
           <id>attach-signed-aligned</id> 
           <phase>package</phase> 
           <goals> 
            <goal>attach-artifact</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 
</project> 
+0

你能更新你的android maven插件到3.5,並檢查是否有幫助。 https://groups.google.com/forum/#!topic/maven-android-developers/w5H0oRWJN9I/discussion也可以讓我知道是什麼問題...我沒有得到...你想使用eclipse中的android-maven插件或通過命令行...問題在哪裏。 – Thalaivar

回答

2

所以事實證明,我只是在Eclipse中手動設置項目時不滿意項目結構。一位同事提到mvn eclipse:eclipse指令是偶然的,這個指令整理了我所有的問題。

參照this示例項目。我做了以下事情,讓Eclipse和Maven中的所有東西都可以使用。

  1. cd到每個項目{莫爾斯lib下,morseflash-應用,morseflash儀表}和運行mvn eclipse:eclipse

  2. 在Eclipse中分別導入每個項目。 不是* -app和* -instrumentation是Android項目,* -lib是 Java項目。所有項目都應該設置爲Java編譯器1.6。

  3. 在Eclipse中每個項目上右鍵點擊 - >配置 - >轉換到Maven

  4. 對於項目{* -app,* -instrumentation},目標/生成的來源/的R - >右鍵 - >屬性 - >資源 - >資源過濾器 - >添加組 - > {排除所有文件和文件夾,所有兒童(遞歸)}

  5. 清潔所有項目然後構建所有

  6. 您現在應該能夠運行morseflash-應用項目作爲一個Android應用程序。

  7. morseflash文件夾中的命令行(含* -lib,* -app,* -instrumentation),你應該能夠execure mvn clean install android:deploy拿到手機上的應用程序。

希望這可以幫助別人。如果沒有,請給我平息

0

嘗試升級到3.5,我建議你去。我還會指定語言級別的源代碼和目標。當我的eclipse完全配置爲不同的版本時,我曾經遇到過這樣的問題。

<plugin> 
    <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
    <artifactId>android-maven-plugin</artifactId> 
    <version>3.4.1</version> 
    <configuration> 
     <sdk> 
      <platform>10</platform> 
     </sdk> 
     <configuration> 
      <source>1.7</source> 
      <target>1.7</target> 
     </configuration> 
     <emulator> 
      <avd>23</avd> 
      <wait>10000</wait> 
      <!--<options>-no-skin</options> --> 
     </emulator> 
     <zipalign> 
      <verbose>true</verbose> 
     </zipalign> 
     <undeployBeforeDeploy>true</undeployBeforeDeploy> 
    </configuration> 
</plugin>