Android Studio cannot resolve symbols from AAR
Asked Answered
C

3

3

My question has the same problem as Issue with using .AAR file in other project. But I want to add more details. Hence the new question.

I am also aware of solutions such as this Android Studio cannot resolve symbols from imported AAR module but the answers aren't exactly what I am looking for.

I can add my AAR file into my project without problem either by adding it in libs/ folder or adding as new AAR module. The problem happens when the AAR authors give an updated AAR (because they changed something in their public API i.e. adding new parameter in one of the old methods).

Android Studio can't seem to pickup the changes. In the old library, I had this method call:

library.showText("hello");

Authors released a new API with update to the same method, and should be called as:

library.showText("hello", 5000); // added timeout param

When I CTRL+click the method, it takes me to the old class that has the method located in C:\Users\MyUser\.gradle\caches\transforms-1\files-1.1\library.aar\...\old.class. I think this is the problem why I get "cannot resolve symbols" error.

How do I fix this?

Cyclotron answered 13/5, 2018 at 7:44 Comment(1)
Related post - Android Studio suddenly cannot resolve symbolsBeverleebeverley
C
4

I guess the problem was Android Studio and Gradle did not agree. Here are three solutions that worked for me (after hours of tests). If one option does not work for you, try the next.

Option 1

  1. Gradle -> Refresh All Gradle Projects

Option 2

  1. Gradle -> Refresh All Gradle Projects
  2. Remove 'build' directories from project
  3. Remove .gradle cache from C:\Users\YOUR_USER_NAME\.gradle\caches\transforms-1\files-1.1\* (only delete the few latest folders)
  4. Build -> Clean Project

Option 3 (this will restart your Android Studio)

  1. File -> Invalidate Caches / Restart
  2. then choose Invalidate and Restart
  3. Gradle -> Refresh All Gradle Projects
Cyclotron answered 14/5, 2018 at 9:43 Comment(4)
There is no gradle menu. I had to go view -> tool windows -> gradle to get the gradle toolbar which has the "refresh" icon.Trichina
Didn't work for me :-( Having said that, I couldn't find Accounts.gradle... in Linux...Animation
@Cyclotron Still doesn't work. Cleared all caches, reimported the .aar file, and still it can't find it. However, I created a new project, imported the .aar file, and now it is working !Animation
great! if after some time, you were able to figure out the root cause, we can go back to this thread and update the answer. cheers!Cyclotron
R
5

I would tell what I had done to correct this error:

  1. Delete this dependency from build.gradle file, and sync, this action will be abort because of missing specified file;
  2. Now revert the build.gradle file, and sync;
  3. Done, everything is OK.
Recrement answered 11/7, 2018 at 8:58 Comment(0)
C
4

I guess the problem was Android Studio and Gradle did not agree. Here are three solutions that worked for me (after hours of tests). If one option does not work for you, try the next.

Option 1

  1. Gradle -> Refresh All Gradle Projects

Option 2

  1. Gradle -> Refresh All Gradle Projects
  2. Remove 'build' directories from project
  3. Remove .gradle cache from C:\Users\YOUR_USER_NAME\.gradle\caches\transforms-1\files-1.1\* (only delete the few latest folders)
  4. Build -> Clean Project

Option 3 (this will restart your Android Studio)

  1. File -> Invalidate Caches / Restart
  2. then choose Invalidate and Restart
  3. Gradle -> Refresh All Gradle Projects
Cyclotron answered 14/5, 2018 at 9:43 Comment(4)
There is no gradle menu. I had to go view -> tool windows -> gradle to get the gradle toolbar which has the "refresh" icon.Trichina
Didn't work for me :-( Having said that, I couldn't find Accounts.gradle... in Linux...Animation
@Cyclotron Still doesn't work. Cleared all caches, reimported the .aar file, and still it can't find it. However, I created a new project, imported the .aar file, and now it is working !Animation
great! if after some time, you were able to figure out the root cause, we can go back to this thread and update the answer. cheers!Cyclotron
H
1

depends on the way, how you import that library:

  • download .aar and store into libs directory - you need to download everytime, when the new version was released and overwrite your current .lib file + Sync gradle/Rebuild project

  • using gradle file with url pointed to that library - Sync gradle (right top bar „Gradle“ - open and click on Refresh icon to reimport libraries)

Hime answered 13/5, 2018 at 7:48 Comment(5)
i am doing the first option. overwrote my old aar file in libs directory, still getting the unresolved errorCyclotron
In that case, you should Invalidate cache of the whole Android studio.Hime
i just did the Refresh Gradle Projects, did not work.Cyclotron
how do you invalidate the cache of the whole AS?Cyclotron
Little help. Hope, that will workHime

© 2022 - 2024 — McMap. All rights reserved.