Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio "cannot resolve symbol String"

I have a small project that was started in Eclipse. I then exported it to a gradle file, and imported it to AS (0.5.7).

At first, not much seemed to work as it should, but after a "build => make project", I didn't seem to get any highlighted errors or so.

So I tried to run the app to an emulated device. Well, the device never launched, and now I get red squiggly lines under mentions of "String", "ArrayList" etc, saying it "cannot resolve the symbol".

What the f?

I have tried cleaning and rebuilding, as well as "sync project with gradle files".

Where do I go from here? I want to get going with developing in AS so bad!

edit: Screenshot of project setup: http://i.imgur.com/ycNyPaT.png

Contents of build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
like image 875
Christofer Ohlsson Avatar asked May 03 '14 13:05

Christofer Ohlsson


People also ask

What is Cannot resolve symbol in Android Studio?

Most often “R cannot be resolved” error appears if there is an issue with some of your resource files. Due to this error, you are unable to build your application. That's why we need to solve this error as it not getting away by just doing a simple restart or hitting Alt+Enter.

What does Cannot resolve symbol mean?

The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.


2 Answers

There is simpler and I think more correct way:

Just select menu item 'File/Invalidate Caches/Restart...'

For me this successfully resolved the issue (was caused by surprising power off of PC)

enter image description here

like image 170
SILINIK Avatar answered Oct 07 '22 06:10

SILINIK


So project arrangement should be as follows:

  • create app folder within your project.
  • within app folder make following folders: libs and src
  • inside src create main folder
  • inside main create java and assets
  • move contents of old src to java
  • move contents of old libs to libs
  • move res folder to src
  • move AndroidManifest.xml to src
  • move assets folder into src
  • create build.gradle inside app folder with following content:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
}
  • create settings.gradle in project root with following content:

include 'app'

  • build.gradle in root should have following structure:

buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } }

like image 25
Jakub Szczygieł Avatar answered Oct 07 '22 05:10

Jakub Szczygieł