android - 不会生成R.java (android-maven-plugin)

标签 android maven

我尝试了不同的目标。 mvn package 导致 package R does not existmvn 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,没有资源,这包含在默认的 apklib 构建生命周期中,并与 .apklib 文件一起生成。

关于android - 不会生成R.java (android-maven-plugin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13128169/

相关文章:

android - 在Android中解压unicode文件名错误

android - 2个应用程序如何知道停止其他视频播放?

maven - 使用 shell 命令设置 Maven 属性

java - Jersey : com. sun.jersey.spi.inject.Errors$ErrorMessagesException

java - com.microsoft.sqlserver.jdbc.SQLServerConnection 和 java.sql.Connection 之间有什么区别

maven - vaadin-maven-archetype - 为什么它会生成三个模块?

java - 处理空列表 - 使用 ListFragment 或 Fragment+ListView 更好?

Android 使用 FFMPEG 从摄像头编码 h.264

android - 注释处理器生成的资源未打包到 APK

java - 什么是 Lambda S3Event 的 AWS SDK V2 类?