Android的库不通过其他项目拉动其资源 [英] Android library not pulling its resources through to other projects

查看:154
本文介绍了Android的库不通过其他项目拉动其资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图使之成为一个库中的Andr​​oid项目。我抛出这个code异常:

I have an Android project that I'm trying to make into a library. I get an exception thrown on this code:

_buttonStart = (Button) findViewById(R.id.buttonStart);

我得到的例外是:

The exception I get is:

java.lang.NoSuchFieldError: com.xxx.libraryname.R$id.buttonStart

Android的文档似乎明确地说,图书馆应该能够访问这些资源:

The Android docs seem to explicitly say that the library should be able to access those resources:

例如,源$ C ​​$ C库中的项目都可以通过它的R级访问自己的资源。

"For example, source code in the library project can access its own resources through its R class."

当我看在图书馆的 /gen/com.xxx.libraryname/R.java/R/id / ,buttonStart是存在的。但是,当我看到在主要项目的 /gen/com.xxx.libraryname/R.java/R/id ,事实并非如此。

When I look in the library's /gen/com.xxx.libraryname/R.java/R/id/, buttonStart is there. But when I look in the main project's /gen/com.xxx.libraryname/R.java/R/id, it isn't.

我已经做了make clean。

I've done a make clean.

推荐答案

您的图书馆项目也有相同的名称布局main.xml中为您的主项目。

Android将优先举办项目如果两者都具有相同的布局名称,在这种情况下的的main.xml最好的办法是,所以没有意外碰撞用一些preFIX符号

Android will give priority to host project if both have the same Layout name, in this case "main.xml" Best approach is to use some prefix notation so there are no accidental collisions.

这篇关于Android的库不通过其他项目拉动其资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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