Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android library not pulling its resources through to other projects

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

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

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

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.

I've done a make clean.

like image 299
Dan Jameson Avatar asked May 03 '12 02:05

Dan Jameson


1 Answers

Your library project also has same name layout main.xml as your main project.

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.

like image 57
AZ_ Avatar answered Nov 15 '22 20:11

AZ_