【问题标题】:R.java will not be generated (android-maven-plugin)不会生成 R.java (android-maven-plugin)
【发布时间】:2012-10-29 19:16:18
【问题描述】:

我尝试了不同的目标。 mvn package 生成 package R does not existmvn android:generate-sources 生成 BUILD SUCCESS,但不会创建 R.java

我想将我的类打包到一个 jar 容器(不是 apk)中,因为我想将它用作其他项目中的库。

AndroidManifest.xml:(最小设置,因为没有活动)

<?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>

default.properties:

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


    【解决方案1】:

    android-maven-plugin 无法从 Android 库项目生成功能齐全的 jar(包含所有已编译的类文件、资源、清单等)。

    android-maven-plugin 给出的解决方案是apklib,它只是库项目的一个zip(具有相同的目录结构,包含原始java文件、资源、清单等)。我已经详细解释了 apklib 的工作原理in this answer,对于一些示例项目,请查看maven-android-plugin-samples/libraryprojects

    android-maven-plugin 最远的地方是一个只包含编译好的类文件,没有资源的 jar,它被默认的 apklib 构建生命周期覆盖,并与 .apklib 文件一起生成。

    【讨论】:

      猜你喜欢
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 2015-02-21
      • 2011-08-16
      相关资源
      最近更新 更多