The import com.android.internal.R cannot be resolved
Asked Answered
M

4

17

Hi i am working with Gestures and i need to import but i m getting error

com.android.internal.R;

The import com.android.internal.R cannot be resolved

kindly help me , please

Memoirs answered 30/12, 2011 at 19:50 Comment(1)
How did the error prop up? Did you change anything in the project setup or added new files manually? If yes, try to clean the project and build it again.Schematize
R
41

You don't say why you need access to com.android.internal.R, but the sad fact is that you simply cannot import it (the "internal" is a clue that it's not part of the public API). Google doesn't expose this because it is subject to change.

It is possible to get to the internal resources by calling Resources.getSystem(). To get the value of a particular resource identifier, you have to know its name and then use code like the following to find the value:

Resources res = Resources.getSystem();
int id = res.getIdentifier("resource name", "resource type", "android");

Be aware that any name that you use could disappear in future versions of Android.

Rivkarivkah answered 30/12, 2011 at 19:56 Comment(2)
Thank you for your response! How can i get resource id this item? ``` <item type="id" name="switch_widget" /> ```Brown
@Brown - Your question is unclear. What you've shown is an id resource definition, which you can reference as R.id.switch_widget in code. Is there something else you have in mind?Rivkarivkah
C
6

I have a couple suggestions:

1) Make sure you don't have any other errors other than the R-related errors. Right-click your project folder in Eclipse, Android Tools -> Fix Project Properties.

2) Check to make sure you have the correct R imported. Sometimes the default Android.R can be imported.

Catawba answered 31/12, 2011 at 6:50 Comment(0)
A
4

Yes you can use the internal R with some dirty trick (dirty trick = Java reflection).

Just an example:

Class clasz = Class.forName("com.android.internal.R$styleable")
Field field = clasz.getDeclaredField("TextAppearance");
field.setAccessible(true);
int[] textAppearanceStyleArr = (int[])field.get(null);

field = clasz.getDeclaredField("TextAppearance_textSize");
field.setAccessible(true);
int textSizeStyle = (Integer)field.get(null);
Aggressor answered 13/11, 2014 at 13:48 Comment(1)
Accessing internal APIs via reflection is not supported and may not work on all devices or in the future!Winze
B
3

First of all, what is Gestures ? Do you have a package named com.android.internal in your gen folder ? Doest it contain R.java ? If not, try Project->Clean in Eclipse. If it still doesn't work, you may have an error in your XML layout files.

Bridgid answered 30/12, 2011 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.