Android Studio can't find library classes after Gradle build
Solution 1
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.
Solution 2
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
Solution 3
Goto File ⇒ Invalidate Caches & Restart
Solved my problem
Solution 4
- As first option, i think will be enough
Syncronizing the Project with Gradle Files
.
- Another option, from the command line, run the batch file
gradlew.bat
located inside your project folder:
./gradlew clean && ./gradlew build
Solution 5
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:
- Close Android Studio
- Delete the .idea folder in the project's directory
- Open Android Studio
- 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.
Related videos on Youtube
tolgap
Updated on May 23, 2021Comments
-
tolgap about 3 years
I'm trying to add a
.jar
library to my project into the/libs
folder. Here is mygrade.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?-
IgorGanapolsky over 10 yearsDo you have any sub-projects, or just one main gradle project? I was getting a similar error in one of my sub-projects...
-
-
IgorGanapolsky over 10 yearsI thought if you run Build -> Rebuild Project it will run assembleDebug task for Gradle, which runs 'clean' task beforehand anyway.
-
ajinkya gaurkar about 8 yearsThank you so much. This command line solution helped. I was tired finding solutions for my problem. But finally this worked
-
Giacomo Mattiuzzi about 7 yearsYou have saved my day!! Thank you so much!!
-
Omid Naji about 5 yearsbest answer, tnx
-
Sal over 3 yearsThe first option worked for me, but the second one not.