Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android library project: R.id cannot be resolved or is not a field

The library project looks fine, but as soon as I import it to my main project, it shows me errors on each line which is referencing a resource:

id cannot be resolved or is not a field

The main project shows no errors.

Of cause I ask myself where android knows where to import the resources from e.g. in lines like that:

RelativeLayout menuLayout = (RelativeLayout) this.findViewById(R.id.menu_layout);

But this works neither:

RelativeLayout menuLayout = (RelativeLayout) this.findViewById(net.bla.library.R.id.menu_layout);

Any Ideas?

EDIT: what I found out is:

As soon as I include the library project, Eclipse duplicates the gen/net.mylibrary.R from the library into the main app (so there are 2 packages in the gen folder now: the one from the app, and the copied one from the library). strange thing is: R.id is not found in the copy. There are some other differences too, like the copy uses an additional "final" for its definitions.

I really have no clue why this might happen. Someone?

like image 751
stoefln Avatar asked Jan 17 '23 23:01

stoefln


1 Answers

Eclipse sometimes likes to import android.R, and this causes errors similar with you are experiencing.

Look for the import at the top of the file, and remove it.

As it's stated on "Using Eclipse | Android Open Source":

Note: Eclipse sometimes likes to add an import android.R statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.

like image 71
Telmo Marques Avatar answered Feb 22 '23 22:02

Telmo Marques