Jonathan Toledo
Jonathan Toledo

Reputation: 359

Import android-support-v7-appcompat within a library project causes: R cannot be resolved to a variable

I have an Android project in which I want to generate two versions, one paid and one with advertising. According read on Stackoverflow, one way to do this is to create a parent project and create 2 child projects who imported the parent as a library. Also I use appcompat, so the hierarchy is as follows:

enter image description here

The problem is that the R class does not compile due to an error, which I can not find. But when the parent project did not configure as library ("Is library unchecked") everything works fine. Here the pictures:

appcompat project in eclipse

appcompat build path

parent project as library and import appcompat and other libs

errors

more errors

Hopefully you can help me, thanks in advance.

Edit: mark's answer resolved the problem with android.support.v7.appcompat.R.id.search_src_text, but I still have errors with the R class, example:

enter image description here

enter image description here

Upvotes: 1

Views: 3473

Answers (2)

Jonathan Toledo
Jonathan Toledo

Reputation: 359

I found the problem. In fact, mark's answer solved part of the errors, but, after reading this post Resource ID In Android Library Project, solved the problem with menu id's.

Thanks.

Upvotes: 1

mark
mark

Reputation: 89

Sorry for my English.

Replace the error line with this:

EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);

Upvotes: 2

Related Questions