Android的Maven插件apklib魔不包括导致apklib编译ř [英] Android Maven Plugin apklib Mojo doesn't include compiled R in resulting apklib

查看:185
本文介绍了Android的Maven插件apklib魔不包括导致apklib编译ř的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图提取了Android / RES 文件夹成随机配备在我的主要项目为apklib依赖一个单独的项目。现在的问题是,虽然内容的 / RES 被包含在最终的 .apklib ,编译 R.class 不是。更令人困惑的是, MVN全新安装命令生成 .apklib ,以及一个的.jar 文件和jar文件具有 R.class ,但没有的 / RES 文件夹。如何生成单包(无论是的.jar或.apklib),它包含了我所有的资源,以及编译的类?

I'm trying to extract the Android /res folder into a separate project that's included in my main project as an apklib dependency. The problem is that while the contents of the /res are included in the resulting .apklib, the compiled R.class is not. Even more confusing is that the mvn clean install command generates the .apklib as well as a .jar file, and the jar file has R.class, but none of the contents of the /res folder. How do I generate a single package (either .jar or .apklib) that contains all of my resources as well as the compiled classes?

的pom.xml

<packaging>apklib</packaging>
...
<plugin>
  <groupId>com.jayway.maven.plugins.android.generation2</groupId>
  <artifactId>android-maven-plugin</artifactId>
  <configuration>
    <attachSources>true</attachSources>
    <sdk>
      <platform>12</platform>
    </sdk>
  </configuration>
<plugin>

生成以下

的.jar

./morseflash-resources.jar
  com/.../R.class    

.apklib

./morseflash-resorces.apklib
  META-INF
  AndroidManifest.xml
  res/
      layout/
      values/

我想在一个文件中的所有这些内容,我希望能够列出它作为我的主要的Andr​​oid项目的依赖。这是可能的,如果是这样,我怎么能做到呢?

I'd like all this content in a single file, and I'd like to be able to list it as a dependency in my main Android project. Is this possible, and if so, how could I accomplish it?

推荐答案

这是Android的Maven的插件是如何工作的,到库项目添加为您的主项目的依赖,添加以下的依赖到你的主项目的pom.xml:

This is how android-maven-plugin is supposed to work, to add the library project as a dependency of your main project, add the following dependency into your main project's pom.xml:

<dependencies>
  <dependency>
    <groupId>com.company.common.lib</groupId>
    <artifactId>common-lib</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <type>apklib</type>
  </dependency>
</dependencies>

请注意,这是与常规的jar依赖不同的是,apklib简直就是所有的的src RES 文件夹中有一个Android / Eclipse的库项目(的src / COM /...而不是的src / main / java下的标准目录结构布局/ COM /...)。其原因是使用apklib其他非mavenlized项目(检查出的有关详细信息,ApkLib文档)。您不添加磁带库作为编译JAR依赖,而是要添加的库的依赖关系为源 - code和资源,简单地从一个zip文件。

Note that this is different from regular jar dependencies, the apklib is simply a zip of all your src and res folders that has the standard directory structure layout of an Android/Eclipse library project (src/com/... instead of src/main/java/com/...). The reason for that is to support using apklib in other non-mavenlized projects (check out the ApkLib documentation for details). You are not adding your library as a compiled jar dependency, instead, you are adding your library dependency as source-code and resources, simply from a zip file.

在做 MVN全新安装,在 Android的Maven的插件:3.0.0:产生-源目标,Android的Maven的插件将其解压缩到apklib依赖和编译项目前合并源 - code和资源投入到您的主项目;这是多么的Andr​​oid库项目都应该工作。图书馆计划不只是单纯的编译一切。为了节省内存和光盘空间仅用于部分复制并编译成最终的apk。您可以在主项目容易地替换掉的资源,因为他们只是更换库的东西,在最后的编译前的合并步骤。

When doing mvn clean install, in the android-maven-plugin:3.0.0:generate-sources goal, android-maven-plugin will unzip your apklib dependency and merge the source-code and resources into your main project before compiling your project; this is how Android Library Projects are supposed to work. The Library Project is not just simply compiling everything. To save memory and disc-space only the used parts are copied and compiled into the final apk. You can override the resources easily in the main project, as they just replace the library stuff at the merge step before final compile.

这是丑陋的,但它是如何工作的那一刻,Android开发团队目前正在就这个问题和将在未来支持的jar依赖,很可能在R17(这也需要Android的Maven的插件改变/升级我猜想),在其官方博客文章的详细信息的在Android的SDK工具更改库项目,R14

It's ugly but it is how things work at the moment, Android Dev team is currently working on this and will support the jar dependency in the future, probably in r17 (which also requires android-maven-plugin change/upgrade I suppose), more details in their official blog post "Changes to Library Projects in Android SDK Tools, r14 ".

这篇关于Android的Maven插件apklib魔不包括导致apklib编译ř的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆