How to import R into Android project? [duplicate]

2019-03-07 05:54发布

问题:

This question already has an answer here:

  • “R cannot be resolved to a variable”? [duplicate] 30 answers

I've downloaded a couple of example Android projects to learn ORMLite. I constantly get this error saying R cannot be resolved to a variable. So I just do a CTRL+Shift+O to automatically import all dependencies. This then inserts import android.R; which unfortunately doesn't solve the problem.

Since the package name is com.test; I tried to do import com.test.R; but that doesn't work either.

Does anybody know how I can solve this?

回答1:

try the next steps (order doesn't matter) :

  1. update ADT & SDK , Eclipse and Java

  2. remove gen folder , and create it again .

  3. do a clean-project.

  4. right click the project and choose android-tools -> fix-project-properties .

  5. right click the project and choose properties -> java-build-path -> order-and-export. make sure the order is :

    • Android 4.3 (always the latest version)

    • Android private libraries

    • android dependencies

    • your library project/s if needed

    • yourAppProject/gen

    • yourAppProject/src

  6. make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") .

  7. always make sure the targetSdk (in the manifest) is pointed to the latest API (currently 18) , and also set it in the project.properties file