【问题标题】:compilation error when using maven apklib使用 maven apklib 时出现编译错误
【发布时间】:2013-09-04 04:07:03
【问题描述】:

我创建了一个库项目并将packing 设置为apklib。在应用程序中,我添加了依赖:

<dependency>
    <groupId>com.ati</groupId>
    <artifactId>common-lib</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>apklib</type>
</dependency>

我在我的应用项目中使用 lib,例如:com.ati.common_lib.Test.demo(); 并使用 mvn clean install。有效!但是如果我使用import com.ati.common_lib;Test.demo();mvn clean build 它会抛出错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project soci-news: Compilation failure: Compilation failure:
[ERROR] /Data/Work/workspace/soci-parent/soci-news/src/main/java/com/ati/soci_news/HelloAndroidActivity.java:[9,15] cannot find symbol
[ERROR] symbol  : class common_lib
[ERROR] location: package com.ati
[ERROR] /Data/Work/workspace/soci-parent/soci-news/src/main/java/com/ati/soci_news/HelloAndroidActivity.java:[23,9] cannot find symbol
[ERROR] symbol  : variable Test
[ERROR] location: class com.ati.soci_news.HelloAndroidActivity
[ERROR] -> [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/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :soci-news

我正在使用 maven 3.0.5,eclipse “kepler 版本”和 m2e-android。我由 m2e-android 创建的库和应用程序。我在这里做错了什么?

更新

我的父 pom.xml

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ati</groupId>
    <artifactId>soci-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Soci project parent</name>

    <modules>
        <module>common-lib</module>
        <module>soci-news</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
                <version>2.2.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

我的库 pom.xml

<?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.ati</groupId>
        <artifactId>soci-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.ati</groupId>
    <artifactId>common-lib</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>apklib</packaging>
    <name>common lib for ati android application</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version> 2.2.1
        </platform.version>
        <android.plugin.version>3.6.1</android.plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

我的应用的 pom.xml

<?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.ati</groupId>
        <artifactId>soci-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.ati</groupId>
    <artifactId>soci-news</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>soci-news</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.ati</groupId>
            <artifactId>common-lib</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>apklib</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

【问题讨论】:

  • 我们能看到你所有的 POM 吗?
  • 找不到您的 HelloAndroidActivity。确保如果你使用它,那么你可以使用它。
  • @alex:我更新了我的问题。
  • @LajosArpad:我确定我的 HelloAndroidActivity 类出现了。

标签: android maven compiler-errors apklib


【解决方案1】:

您的导入已损坏。

com.ati.common-lib 是包,但您确实想导入该包的内容,com.ati.common-lib.* 用于所有内容,com.ati.common-lib.Test 仅用于 Test 类。

【讨论】:

  • 我尝试在每个 maven 项目(lib 项目、app 项目和父项目)中使用 mvn clean package 和 mvn clean install,但没有运气。在父项目或应用项目中使用时出现编译错误。我真的不明白你的想法,所以我想知道这个错误是否可以修复?
  • 你可以试试 import com.ati.common_lib.*;或导入 com.ati.common_lib.Test;
  • 好的!!!它的工作,非常奇怪:))。非常感谢。如果你不介意,我可以再问你一个问题:在这张图片中imgur.com/5lvgPkq 是我的eclipse 文件编辑器。 Eclipse 无法识别 R 文件、测试类...等,当然它也不会显示代码建议,因为我通常使用没有 maven 的普通 android 项目。你知道为什么吗?以及如何修复它?对不起这个幼稚的问题,因为我是 Maven 的新手。非常感谢。
  • 我认为您应该更新您的答案以导入 com.ati.common_lib.*;供以后的人理解。
猜你喜欢
  • 1970-01-01
  • 2011-07-26
  • 2017-01-06
  • 1970-01-01
  • 2018-07-10
  • 2014-02-02
  • 2020-09-19
  • 1970-01-01
  • 2013-06-16
相关资源
最近更新 更多