依赖于外部apklib时Eclipse编译错误

时间:2014-01-14 08:06:58

标签: android maven m2e android-maven-plugin

我有几个Android库项目,我正在尝试转换为Maven。

我遇到了 mvn clean install 成功的问题但在Eclipse中存在导入问题,好像project2 apklib中的类不在project1的类路径中。

第一个项目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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>android-clientsdk</artifactId>
<packaging>apklib</packaging>

<parent>
    <groupId>com.company.client</groupId>
    <artifactId>company-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <path>${android.sdk.path}</path>
                    <platform>${android.sdk.platform}</platform>
                </sdk>
                <!-- <deleteConflictingFiles>true</deleteConflictingFiles> -->
            </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>[3.7.0,)</versionRange>
                                    <goals>
                                        <goal>generate-sources</goal>
                                        <goal>consume-aar</goal>
                                        <goal>proguard</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[2.1,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>android-clientelement</artifactId>
<packaging>apklib</packaging>

<parent>
    <groupId>com.company.client</groupId>
    <artifactId>company-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <path>${android.sdk.path}</path>
                    <platform>${android.sdk.platform}</platform>
                </sdk>
                <!-- <deleteConflictingFiles>true</deleteConflictingFiles> -->
            </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>[3.7.0,)</versionRange>
                                    <goals>
                                        <goal>generate-sources</goal>
                                        <goal>consume-aar</goal>
                                        <goal>proguard</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <versionRange>[2.1,)</versionRange>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.company.client</groupId>
        <artifactId>android-clientsdk</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>apklib</type>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.0.1</version>
    </dependency>
</dependencies>

技术的:

  • 我正在使用Eclipse Kepler。
  • 我正在使用M2E的最新Android Configurator(取自eclipse市场)

我的问题:

  1. 当依赖于apklib时,我们是否应该在Eclipse中看到有关此依赖项的任何证据(如从此库中编译的.class)?
  2. 为什么Eclipse无法从依赖的apklib中的包中找到导入?

1 个答案:

答案 0 :(得分:0)

您必须在Eclipse工作区中导入APKlib,然后将其链接到您的主应用程序项目(项目属性&gt; Android&gt;添加库并选择您的APKLib项目)

有时,如果您执行maven项目的清理或更新,Eclipse会丢失apklib的链接,您必须再次添加它。