This question has been discussed a lot, but the problem is that Android Studio has changed a lot in past few months and for example the Project Structure dialog window is now completely different. So many solutions don't work anymore, at least for me.
If I understand it correctly, there are two separate issues to be solved when importing external JARs (or generally using external libraries).
- I have to configure the jar as a Gradle dependency so it would compile with the rest of my code.
- I have to let Android Studio know that I'm using this jar as a library so I would get autocomplete and other IDE stuff working.
I managed to solve the first problem. I put the jar file into build.gradle to dependencies { ... }
and when I use some class contained in the jar file, it builds and runs with no errors (and when I remove it from dependencies
it crashes so I would say it works as expected).
But I have a problem with the second part. I added the jar file as a library using rightclick on the file in the sidebar and I can now expand the jar and see all contained classes. However, Android Studio still doesn't recognize these classes when I use them in my code (which is in separated module/folder). Any ideas how to fix it?