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

15,621

Solution 1

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.

Solution 2

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);

Solution 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.

Share:
15,621

Related videos on Youtube

Mercy
Author by

Mercy

Android Developer

Updated on June 04, 2022

Comments

  • Mercy
    Mercy almost 2 years

    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

  • Mir-Ismaili
    Mir-Ismaili over 6 years
    Accessing internal APIs via reflection is not supported and may not work on all devices or in the future!
  • nAkhmedov
    nAkhmedov over 6 years
    Thank you for your response! How can i get resource id this item? ``` <item type="id" name="switch_widget" /> ```
  • Ted Hopp
    Ted Hopp over 6 years
    @nAkhmedov - 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?