我用 Maven 解决了同样的问题。诀窍是将公共库仅包含在主机应用程序中,而不是将其包含在插件中。
这是我的项目的一部分。
公共库 pom
将其构建为 andriod 库(使用 apklib 打包)并使用 build-helper-maven-plugin 安装额外的 *jar 文件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/target/${project.build.finalName}.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
主机应用程序的 pom
包含对公共库的依赖关系
<dependency>
<groupId>group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>common-library-version</version>
<type>apklib</type>
</dependency>
插件的 pom
在提供的范围内使用 *.jar 依赖项。Apklib 依赖项不支持提供的范围。
<dependency>
<groupId>your.common.library.group</groupId>
<artifactId>Your-common-lib-id</artifactId>
<version>your-common-lib-version</version>
<scope>provided</scope>
</dependency>
最后创建某种汇编程序项目并将所有三个项目都包含在它的 pom 文件中。
它适用于我的 maven3 和 android-maven-plugin 3.2.0