How to import R into Android project? [duplicate]

2019-03-07 05:12发布

This question already has an answer here:

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条回答
我想做一个坏孩纸
2楼-- · 2019-03-07 05:56

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

查看更多
登录 后发表回答