20

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: https://i.stack.imgur.com/KOqaO.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')
    }
}
4
  • can you add screenshot of your Android Studio project setup and build.gradle content. May 3, 2014 at 14:04
  • I would advise creating new project and then rearraning your project folderu acordingly. then delete while sourceSets part from gradle and rerun sync May 3, 2014 at 14:20
  • So step 1) I create a new project. Step 2) - how do I get my files into this project so that the project folder is set up properly? I have no idea what it's supposed to look like. May 3, 2014 at 14:35
  • 1
    give me 40min i will get to computer and make screenshot of proper project setup. May 3, 2014 at 14:40

7 Answers 7

36

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

3
  • 4
    After using "Invalidate Caches / Restart..." I got new errors. Mar 6, 2017 at 17:21
  • 1
    "Invalidate Caches / Restart..." did not work for me. I ended up with the following error: "Gradle 'buildingproject' project refresh failed. Failed to open zip file. Error: Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)". What are the potential side-effects of using "Invalidate Caches / Restart..."? Mar 6, 2017 at 23:44
  • WOW it works like a charm! I have this issue due to windows blue screen too!
    – ch271828n
    Aug 15, 2017 at 12:36
4

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.+' } }

6
  • Thank your for your help so far. I now get "project refresh failed. Error: Cause: unexpected end of block data" i.imgur.com/5z1KdEs.png May 4, 2014 at 8:36
  • Res, assets and AndroidManifest.xml should be under main folder May 4, 2014 at 8:45
  • Okay, I moved them back. Still getting the same error. May 4, 2014 at 9:01
  • What android build tools do you have installed. You can check that under sdk manager. Project is setup to user 19.0.1, you can download the newest (19.0.3) and change build.gradle file acordingly. May 4, 2014 at 9:08
  • I seem to have just about every version installed. i.imgur.com/buFk6eQ.png so I changed to 19.0.3, still the same error. May 4, 2014 at 9:11
2

Android Studio 4.2.1 with Gradle 7.0.2.

Just had this problem with a module in my project. Basically many fundamental symbols like String, @Override there are not resolved. Non of the syncing or deleting cache etc helped me. The project builds without problem though, and after a successful build, the problem remained.

It turns out the issue relates to the line in the build.gradle file of the module:

apply plugin: 'java-library'

I had it there for ages and I haven't opened the module in a long time, so probably since some newer version of Gradle it's not accepted.

So the solution for me is to change the line to:

apply plugin: 'com.android.library'
1
  • The idea is to create and use Java module in your Android project. When you write apply plugin: 'com.android.library' you turn your Java module into Android module. Feb 1, 2022 at 23:28
1

Just writing this for people like me, who also landed here through googling this error. What actually solved it for current Android Studio 3.1.+ was this

1

You just need to sync the project as you have opened an external project from a zip file in the android studio. After you sync the project, you will see folders like Java,res folder,etc, instead of these not useful folders. And also, all the errors will be gone too.

When you open the external project, it will show like this. https://photos.app.goo.gl/BFa113X9DWH8eNDt7

Then you click on the install, it will install the required components required for the project and then it will sync the project. After syncing, the Gradle will be build and your project is ready to run.

1
  • How do you "sync the project"?
    – Nico Haase
    Jun 28, 2018 at 14:15
0

Remove the following line from the file that reported with the error if there is.

import static com.google.android.gms.internal.a.R;
0

try deleting [project]/[module]/build folder. and then rebuild the project from menu->build->rebuild project thats what worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.