我尝试了不同的目标。 mvn package
导致 package R does not exist
,mvn android:generate-sources
导致 BUILD SUCCESS
但是没有R.java
将被创建。
我想将我的类打包到一个 jar 容器(不是 apk)中,因为我想将它用作其他项目中的库。
AndroidManifest.xml:(最小设置,因为没有 Activity )
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
</manifest>
默认属性:
android.library=true
target=android-8
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>
<groupId>com.example</groupId>
<artifactId>mylib</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.4.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
唯一的资源是./res/layout/example.xml
。
最佳答案
android-maven-plugin 无法从 Android 库项目生成功能齐全的 jar(包含所有已编译的类文件、资源、 list 等)。
android-maven-plugin给出的解决方案是apklib ,它只是库项目的一个 zip(具有相同的目录结构,包含原始 java 文件、资源、 list 等)。我已经详细解释了 apklib 的工作原理 in this answer , 对于一些示例项目,请查看 maven-android-plugin-samples/libraryprojects .
最远的 android-maven-plugin 可以是一个只包含编译类文件的 jar,没有资源,这包含在默认的
关于android - 不会生成R.java (android-maven-plugin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13128169/