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')
    }
}
Christofer Ohlsson
  • 3,097
  • 4
  • 39
  • 56

7 Answers7

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

SILINIK
  • 988
  • 7
  • 16
  • 4
    After using "Invalidate Caches / Restart..." I got new errors. – Jaime Montoya Mar 06 '17 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..."? – Jaime Montoya Mar 06 '17 at 23:44
  • WOW it works like a charm! I have this issue due to windows blue screen too! – ch271828n Aug 15 '17 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.+' } }

Jakub Szczygieł
  • 1,203
  • 1
  • 13
  • 26
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'
LXJ
  • 1,180
  • 6
  • 18
  • 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. – Ildar Zaripov Feb 01 '22 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

Thommy
  • 5,070
  • 2
  • 28
  • 51
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.

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;
Ken Ratanachai S.
  • 3,307
  • 34
  • 43
0

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

Muhammad Ahmed
  • 144
  • 1
  • 8