Why doesn't the Android build system include R.class in the library project and how to fix it?

In Eclipse, I converted an android application project to a library project. The library is used by other application projects.

The file R.java

is generated in the library, but when I check the file .jar

it is not there.

The library file R

is in the package: com.library.R.java

. In my application com.app.R.java

. The library needs to be used R

from the library and imported com.library.R

, but it was not found. The file com.app.R

contains all definitions from the library and application.

Why doesn't the Android build system include R.class

libraries in the project and how to fix it?

+3


source to share


3 answers


you need to use getResources().getIdentifier()

i.e. getResources().getIdentifier("home", "id", "android.support.v7.appcompat")



http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29

+2


source


I don't know why, but this is the expected behavior, check

http://tools.android.com/recent/dealingwithdependenciesinandroidprojects



Important change: We changed the way Library projects are created and R-class classes: R-class is not packaged in the output in the library project bank. The library project does not generate an R class for the library projects on which they depend. Only the main application projects generate R library classes along with their own.

Does anyone know why this change?

+1


source


I don't know exactly how I fixed this, but I tried a lot of things, including full restore, etc. Which ended up solving, although it was removing the R.java library and then rebuilding. Somehow this caused the addition of com.library.R.java to the gen folder in the application project, which seems to have happened in the first place.

0


source







All Articles