I also had a βcan't find character variable ...β error in the R.id element defined in the library project. It is noteworthy that only R.id characters were not resolvable in the main project, although other R-fields (for example, R.layout) were clearly visible.
Fortunately, I was able to stumble upon a solution. It turned out that in my case I had a resource (layout file) defined in my main project, which had the same name as in the library project.
It was like a file system:
top_level_project main_android_proj src main res layout activity_main.xml android_library_subproject src main res layout activity_main.xml
In my subproject activity_main.xml there was such an identifier:
<RelativeLayout....> <TextView android:id="@+id/special_text" ... /> </RelativeLayout>
And this is how I try to reference id in my main Java project project:
MainActivity.java: public void onCreate() { setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.special_text); tv.setText("Hello Android"); }
To fix this problem, I renamed the offending file in my main project to something else.
It seems that you cannot duplicate layout names in your resources. Indeed, sdk docs indicate that you should be careful with resource name conflicts when using library projects:
Because the tools combine the resources of the project library with the projects of the dependent application, this Resource Identifier can be defined in both projects. In this case, the tools select the application resource or library with the highest priority and refuse another resource. When developing, keep in mind that shared resource identifiers are likely to be defined in more than one project and will be combined with the resource from the application or library with priority.
hopia source share