问题
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?
回答1:
I would tell what I had done to correct this error:
- Delete this dependency from build.gradle file, and sync, this action will be abort because of missing specified file;
- Now revert the build.gradle file, and sync;
- Done, everything is OK.
回答2:
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
- Gradle -> Refresh All Gradle Projects
Option 2
- Gradle -> Refresh All Gradle Projects
- Remove 'build' directories from project
- Remove .gradle cache from C:\Users\YOUR_USER_NAME\.gradle\caches\transforms-1\files-1.1\* (only delete the few latest folders)
- Build -> Clean Project
Option 3 (this will restart your Android Studio)
- File -> Invalidate Caches / Restart
- then choose Invalidate and Restart
- Gradle -> Refresh All Gradle Projects
回答3:
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)
来源:https://stackoverflow.com/questions/50313885/android-studio-cannot-resolve-symbols-from-aar