tolgap
tolgap

Reputation: 9778

Android Studio can't find library classes after Gradle build

I'm trying to add a .jar library to my project into the /libs folder. Here is my grade.build:

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

    dependencies {
        compile files('libs/android-support-v4.jar', 'libs/java-api-wrapper-1.2.0-all.jar')
    }

    android {
        compileSdkVersion 17
        buildToolsVersion "17.0.0"

        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 16
        }
    }

After I add that, I build my project and there are no errors. But when I try to use the class in my code private ApiWrapper wrapper, I get an error:

Gradle: error: cannot find symbol class ApiWrapper

I can't quite find where the error is. Is my grade.build not ok, or am I supposed to build it some other way?

Upvotes: 27

Views: 44992

Answers (6)

PKS
PKS

Reputation: 763

Go to the Android studio File and press Invalidate Caches/Restart. This worked for me to find the library

Upvotes: 0

Phani varma
Phani varma

Reputation: 475

Goto File ⇒ Invalidate Caches & Restart

Solved my problem

Upvotes: 16

Michael Osofsky
Michael Osofsky

Reputation: 13135

I had a similar situation where Android Studio couldn't find a library that definitely existed. Even though I was able to compile my project in Android Studio, run it from Android Studio in the emulator or on a physical device, and build it from the command line using gradlew, the Android Studio IDE complained Cannot resolve symbol 'ConstraintLayout'. I believe I had imported the library correctly because I followed Google's instructions: https://developer.android.com/training/constraint-layout/#add-constraintlayout-to-your-project.

Anyway, I ended up solving the problem as follows:

  1. Close Android Studio
  2. Delete the .idea folder in the project's directory
  3. Open Android Studio
  4. Re-import the project so Android Studio can regenerate the .idea folder

This in-fact solved the problem. I believe Android Studio somehow corrupted the .idea folder when I had done "Android Studio" > "Check for Updates" earlier in the day.

Upvotes: 4

Jorgesys
Jorgesys

Reputation: 126455

  • As first option, i think will be enough Syncronizing the Project with Gradle Files.

enter image description here

  • Another option, from the command line, run the batch file gradlew.bat located inside your project folder:

enter image description here

./gradlew clean && ./gradlew build

Upvotes: 10

Vinay
Vinay

Reputation: 1899

Set minifyEnabled to false for all your library projects in build.gradle. See accepted answer by Scott Barta in this thread.

See accepted answer by Scott Barta in this thread

Upvotes: 18

lukasz
lukasz

Reputation: 3131

Using the command line, in the root of your project, run :
./gradlew clean && ./gradlew build

Then recompile your project in studio and you should see your new lib.

Upvotes: 28

Related Questions