问题描述
我有一个库
的项目设置和依赖于该库项目一期工程 - 一切都编译好,我有过的相关
项目运行但罚款;
I have a Library
project set up and a project which depends on this library project - Everything compiles fine and I've had the Dependent
project running fine however;
我是有但是在使用的活动从的间歇性问题库
的项目。
I'm have an intermittent problem however while using an Activity from the Library
project.
我的库
的项目可以是未登记作为库项目和选择器的活动可以孤立地运行。运行在它自己的权利库
项目工作正常,没有问题。
My Library
project can be "unchecked" as a library project and the "picker" Activity can be run in isolation. Running the Library
project in it's own right works fine with no problems.
当我使用库
项目(与机械手活动),从依赖项目它给了我两种 NullPointerException异常
(或历史DexOp)错误的话说,选择器的活动无法找到它的资源。
When I use the Library
project (and the "picker" Activity) from the dependent project it gives me either NullPointerExceptions
(or historically DexOp) errors saying that the "picker" Activity can't find it's resources.
谁能告诉我,如果他们有这样的经历过了?
Can anybody tell me if they have experienced this before?
修改
手动复制 layout.xml
使用的库
项目活动的相关项目,使项目开机械手活动正常。这是必需的?当然不是?这进一步使我不知道是否有与合并/从 R.java
在引用整数ID的一个问题库
项目。
Manually copying the layout.xml
used by the Library
project activity to the dependent project makes the project open the "picker" Activity correctly. Is this required?! Surely not? This further makes me wonder if there is a problem with merging/referencing the integer id's from R.java
in the Library
project.
修改
我不知道这是任何后果,但我的库
项目之一是围绕一组在不同的前端工程中使用自定义视图的包装。
I'm not sure if this is of any consequence, but one of my Library
projects is a wrapper around a set of custom views used in different front end projects.
这些自定义的视图均具有活性,因此它们可以单独测试。
These custom views each have an Activity so that they can be tested in isolation.
其中一个观点的都有自定义属性,在隔离工作运行的同时,很好。但是,它似乎并不像依赖项目正确地拉在属性,并保持公司在原来的命名空间,导致进口布局的抛出编译错误:
One of these view's has custom attributes, which while running in isolation work very well. However, it doesn't seem like the dependent project correctly pull's in the attributes and keep's them in their original namespace, causing the imported layout's to throw compilation errors:
[2012-05-16 12:07:28 - Project] D:\opt\workspace\CustomGlowList\res\layout\main.xml:14: error: No resource identifier found for attribute 'listId' in package 'com.company.library.glowlist'
[2012-05-16 12:07:28 - Project] D:\opt\workspace\CustomGlowList\res\layout\main.xml:14: error: No resource identifier found for attribute 'type' in package 'com.company.library.glowlist
修改
DexOp错误被移除这是present在相关
项目重复的文件名解决。不知道文件名是问题或文件的内容。
DexOp errors were solved by removing a duplicate file name which was present in the Dependent
project. Not sure if the file name was the problem or the contents of the file.
修改
我一直无法找到一个解决这个问题作为然而(尽管@ yorkw的回答肯定与XML属性帮助!谢谢)。
I've been unable to find a solution to this problem as of yet (although @yorkw's answer certainly helps with the xml attributes! Thanks).
我已成功地使这个问题间歇但是:
I have managed to make this problem intermittent however:
我已经通过每一个库项目的消失,并确保他们都有自己的命名空间(即 com.company.library.component1
, com.company.library.component2
等)。经过几个干净的(排序,正确的precedence每一个项目)这个问题自行解决,然而并围绕库/不是图书馆切换到测试组件时,最终还是回来了。
I have gone through each of the library projects and ensured they all had their own namespace (ie, com.company.library.component1
, com.company.library.component2
etc). After a couple of clean's (each project ordered with the correct precedence) this problem resolves itself, however does eventually come back when switching around library/not a library to test components.
推荐答案
这个问题正在从每个图书馆所造成的
项目没有正确正在兴建和参考。资源文件是建立并直接从主叫项目中引用。研究
文件
The problem was being caused by the R
files from each of the Library
projects not correctly being built and referenced. The resource files are built and referenced directly from the calling project.
每个库
需要有独特的包装如的AndroidManifest.xml
定义。这导致每一个它的资源被编译在调用项目旁边的库
罐子内唯一的命名空间包含类
文件。
Each of the Libraries
need to have unique package as defined in the AndroidManifest.xml
. This leads to each of it's resources being compiled in that unique namespace within the calling project alongside the Library
jar which contains the class
files.
之间的一个图书馆和一个可运行的项目进行切换,因为清理并生成
需要发生重新生成这些文件,因为它不能自动完成的时候,当问题变得断断续续行事时unclicking的用作库
复选框,在那里作为罐子(和Java类)并不需要太多哄它们被正确引用作为库项目引用它们作为库
。
The problem becomes intermittent when switching between a library and a runnable project because a clean and build
needs to take place to regenerate these files as it isn't done automagically when unclicking the Use as library
checkbox, where as the jar (and java classes) don't require as much coaxing for them to be correctly referenced as the library projects references them when acting as a Library
.
这可能会导致间歇性的,也是不同的错误包括失踪参考, DexOp
和 NullPointerException异常
s取决于什么度 R.java
文件已被错位或部分建成和正在服用的冲突包之间的地方。
This can lead to intermittent and also varying errors including missing references, DexOp
and NullPointerException
s depending on to what degree the R.java
files have been mangled or partially built and what conflicts are taking places between packages.
这篇关于使用活动从库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!