Android Studio cannot resolve R in imported project?

后端 未结 30 2031
名媛妹妹
名媛妹妹 2020-11-30 02:27

I\'m trying the new Android Studio. I\'ve exported a project from eclipse, using the build gradle option. I\'ve then imported it in Android Studio. The R.java file under gen

相关标签:
30条回答
  • 2020-11-30 03:03

    Follow the five steps below:

    1. Step 1 ===>Delete(CTRL X) the additional tag(s) in XML manifest file.
    2. Step 2 ===>Open Build-->Clean project.
    3. Step 3 ===>Open XML manifest file and past the last additional tag(s) like: Tag Manifest file example: (<uses-permission android:name="android.permission.VIBRATE"></uses-permission>)
    4. Step 4 ===>Step 2 again.
    5. Step 5 ===> Open Tool-->Android-->Sync project with 'Gradle'.

    I have had the same problem but after all the steps it's work for me.

    0 讨论(0)
  • 2020-11-30 03:03

    I solve that problem setting JAVA_HOME, CLASSPATH.

    People sometimes skip JAVA_HOME and CLASSPATH when setting Java_path.

    So try to check Environment Variable.

    CLASSPATH -> .;

    JAVA_HOME -> C:\Program Files\Java\jdk(version) or where Java installed

    and then check the xml file which can have error(Do not naming well-known things such as button,text etc)

    0 讨论(0)
  • 2020-11-30 03:04

    None of these answers helped me!

    My problem was not a problem! The program could compile completely and run on the device but the IDE has given me an annoying syntax error. It has underlined the lines of codes that included "R.".

    The way that I could solve this issue:

    I just added these three classes in "myapp/gen/com.example.app/" folder:

    BuildConfig

    package com.example.app;
    public final class BuildConfig {
        public final static boolean DEBUG = true;
    }
    

    Manifest

    package com.example.app;
    public final class Manifest {
    }
    

    R

    package com.example.app;
    public final class R {
    }
    
    0 讨论(0)
  • 2020-11-30 03:05

    In my case, I found that "android.R.layout.account_list" was referenced instead of "R.layout.account_list". Simply remove "android." can fix the problem. Hope this help because sometimes you may overlook when you are too focusing.

    0 讨论(0)
  • 2020-11-30 03:06

    You should check all your files if it don't have errors and again rebuild your project in:

    • Build > Rebuild Project.

    Or in:

    • File > Settings > Build, Execution, Deployment > Compiler

    Check use external build and after rebuild the project.

    0 讨论(0)
  • 2020-11-30 03:06

    The solution posted by https://stackoverflow.com/users/1373278/hoss above worked for me. I am reproducing it here because I cannot yet comment on hoss' post:

    Remove import android.R; from your activity file in question.

    My setup:

    Android Studio 1.2.2

    Exported project from one Mac to Git (everything was working). I then imported the project on another Mac from Git. Thats when it stopped resolving the resource files.

    I tried everything on this thread:

    1. invalidating cache and restart
    2. Delete .iml files and .idea folder and reimport project
    3. Clean and Rebuild project

    Nothing worked except removing import android.R; from my activity java file.

    To avoid this issue in the future add .idea folder to your .gitignore file. There is a nice plugin from git for gitignore in Android Studio. Install this plugin and right click in .idea > Add to .gitignore

    0 讨论(0)
提交回复
热议问题