Maven 使用库项目在 Android 项目上构建,导致重复的 R 类错误
我有一个依赖于 android 库 (apklib) 项目的 Android 项目。这些项目在 Eclipse 中构建得很好,但我使用 maven 的命令行构建失败,抱怨重复的 R 类(来自我的 android 库项目的 R 类)。
在我的目标文件夹中,我有三个子目录。
- 类:编译后的类文件(像往常一样)。
- generated-sources:为主项目和库项目生成的 R.java。
- unpack :我的库项目的内容,包括清单、资源 xml 文件和生成的 R.java 文件。
“解压”文件夹的存在及其内容是否符合预期?其中的 R.java 文件导致重复的 R 类构建失败。
I have an Android project that depends on an android library (apklib) project. The projects builds fine within Eclipse but my command line build using maven fails complaining of duplicate R class (the R class from my android library project).
Inside my target folder I have three subdirectories.
- classes : the compiled class files (as usual).
- generated-sources: the generated R.java for both the main project and the library project.
- unpack : the contents of my library project including the manifest, the resource xml files and the generated R.java file.
Is the presence and contents of the 'unpack' folder to be expected? The R.java file within it is causing the duplicate R class build failure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用最新版本的 Android Maven 插件 (3.0.1) 0) 并查看如何设置 apklib 使用的示例 。那会解决你的问题。
I would suggest to use the latest version of the Android Maven Plugin (3.0.0) and look how the samples for apklib usage are set up. That will solve your problem.
我错误地设置了库项目的 pom.xml 。我明确地将生成的 java 文件包含在 build/resources 下(从另一个项目复制 pom.xml 文件的产物)。删除它就消除了解压目录中重复的 R.java 文件。解包目录确实存在并且与问题中发布的结构匹配。
顺便说一句,如果我运行“mvncompile”,则库项目示例会失败,但对于“mvninstall”则工作正常。我是一名内行专家,所以这可能是合理的。
I had setup the library project's pom.xml incorrectly. I was explicitly including the generated java files under build/resources (artifact of having copied the pom.xml file from another project). Removing that eliminated the duplicate R.java file in the unpack directory. The unpack directory does exist and matches the structure posted in the question.
BTW, the libraryprojects sample failed if I ran 'mvn compile', but works fine for 'mvn install'. I am a maven n00b, so this may be reasonable.