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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With