android-maven-plugin 和库项目

标签 android maven

这是我的图书馆项目中的 pom.xml。 我执行“mvn clean install”,一切正常。在我的本地 m2 存储库中,我有 apklib Artifact 。

    <?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>
    <artifactId>actionbar</artifactId>
    <groupId>com.markupartist.android</groupId>
    <name>android-actionbar</name>
    <packaging>apklib</packaging>
    <version>1.0</version>


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

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>


    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>android-maven-plugin</artifactId>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <version>3.3.0</version>
                <configuration>
                    <sdk>
                        <path>
                            e:\Program Files\Android\android-sdk\
                        </path>
                    </sdk>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这个 pom.xml 来 self 的主要项目,它依赖于上述项目。

<?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.main.app</groupId>
    <artifactId>VirtualRecruiter</artifactId>
    <version>1.0</version>
    <packaging>apk</packaging>
    <name>MainApp</name>

    <properties>
        <platform.version>2.2.1</platform.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.roboguice</groupId>
            <artifactId>roboguice</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>actionbar</groupId>
            <artifactId>com.markupartist.android</artifactId>
            <version>1.0</version>
            <type>apklib</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <path>
                            e:\Program Files\Android\android-sdk\
                        </path>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

IntelliJ 可以很好地看到我的依赖性,但是当我在主项目上运行“mvn clean compile”时,我得到: F

ailed to execute goal on project MainApp: Could not resolve dependencies for project com.main.app:MainApp:apk:1.0: Could not find artifact actionbar:artist.android:apklib:1.0

当我使用“systemPath”并使用我的 Artifact 的硬编码路径时,maven 可以找到依赖项,但我有编译错误并且 javac 看不到库项目中的任何类。

最佳答案

在您发布的代码中,您犯了一个小错误,也许它会解决您的问题。

您在依赖项上反转了 groupIdartifactId,因此 Maven 无法找到它。

<dependency>
  <groupId>actionbar</groupId>
  <artifactId>com.markupartist.android</artifactId>
  <version>1.0</version>
  <type>apklib</type>
</dependency>

关于android-maven-plugin 和库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11994210/

相关文章:

java - 计算估计的剩余下载时间

java - maven-jar-plugin 与 maven-source-plugin 不起作用

android - 将Gradle 2.1.0更新为2.2.1后出现NoClassDefFoundError

java - 使用 Karaf 的 features-maven-plugin maven 插件需要帮助... osgi

eclipse - 我应该如何向maven项目及其源文件添加许可证信息

java - Hadoop 构建在 Windows 中失败 : zconf. native.sln 中缺少 h?

android - 如何防止静态字段中上下文类导致的内存泄漏

android - 如何在 Android 市场应用程序中显示我的 Android 应用程序列表

android - 我应该实现 onRetainNonConfigurationInstance 吗?

android - 删除 Android 应用程序周围的绿色边框