42

I created two Android Studio applications. One of them is aar library. I used this aar library in second application. I added aar library by using File->New->New Module->Import AAR/JAR Packages option. after that I can see decompiled sources of my aar library. When I update aar library I copy and paste new aar file to my application project folder. But this time Android Studio shows older decompiled sources. But compile new source successfully. How can I update decompiled sources in Android Studio ? when I import aar file implementation project(':app-debug') line was added my build.gradle file.

I am using Android Studio 3.0.1

my solution

the only way I can find to update local sources is clicking Sync Project with Gradle Files button after updating aar/jar file.

utarid
  • 1,642
  • 4
  • 24
  • 38
  • Do the old and new aar files have the same version or are they different versions? – Cliabhach Dec 04 '17 at 20:14
  • do you mean versionCode in build.gradle ?. I did not change it. – utarid Dec 05 '17 at 15:49
  • Yes, I meant that. If you change the versionCode Android Studio should check more thoroughly for the sources. – Cliabhach Dec 08 '17 at 00:03
  • @Cliabhach, I tried that. but situation is same. – utarid Dec 12 '17 at 13:52
  • Hmm. Maybe if you try the `Invalidate Caches` command? https://www.jetbrains.com/help/idea/2016.1/cleaning-system-cache.html?origin=old_help – Cliabhach Dec 12 '17 at 18:26
  • unfortunately it is not work. situation is same. – utarid Dec 14 '17 at 16:38
  • Ugh. This is weird. Um....the aar file should be referenced in your application's build.gradle file. It should look like `implementation files("my_cool_library.aar")` or `implementation "com.example.projects:cool_library:1.1"` Does that exist? You can add it to the question if it does. – Cliabhach Dec 14 '17 at 21:48
  • @Cliabhach, I updated my question – utarid Feb 20 '18 at 06:15

6 Answers6

61

I was having the same issue, had tried every form of including my local aar in my project, tried every method of rebuilding, invalidating caches etc, but I was still having the problem where changes in my local aar were not available after updating the file in the libs folder.

The only thing that worked for me was this:

  1. Comment out the implementation files('../libs/yourlib.aar') line in gradle
  2. Sync gradle
  3. Update yourlib.aar in the libs folder
  4. Uncomment the implementation files('../libs/yourlib.aar') line in gradle
  5. Sync again
  6. Build project

Now the changes in yourlib.aar should be available in your project. If you have this lib included in multiple modules I am guessing you'll have to do it for each module. Not ideal, but I spent at least 5 hours on this issue and these steps were the only way I could seemingly force the changes. I am guessing that removing the library from the gradle file and then syncing will force it to pick up the new one when it is added again.

27

I had the same issue and solved it very quickly doing the following:

  • Look in your project /.idea/libraries/ folder for Gradle__artifacts_[subproject].xml
  • Delete this file
  • In Android Studio, go to File->Sync Project with Gradle Files

This is for an AAR included as a project (which is how it is included when you use File->New->New Module...->Import .JAR/.AAR Package).

Regular User
  • 682
  • 7
  • 16
  • 2
    Thanks your answer, which saves my day. – York Oct 18 '18 at 10:13
  • 1
    Thats the only valid solution which actually could be implemented in the CI without updating library version. Should be marked as accepted answered and Android Studio development team should fix this years ago. – Mateusz Wlodarczyk Oct 25 '18 at 08:00
  • It's useful - but do you not still have to manually copy the .aar files from the Library project to the project actually using the library? – Bad Loser Apr 01 '19 at 07:29
5

Right now you're including the AAR through a project notation. Since an AAR is literally just a file, it should be included with the files notation instead.

Assuming a folder structure like so:

screenshot of the folder directory of a new Android Studio 3 project

You could include the files with any of the following lines in the dependencies block of app/build.gradle:

  // include just my_library
  implementation files('libs/my_library.aar')

  // include just other_library
  implementation files("$rootDir/common/libs/other_library.aar")

  // include both libraries
  implementation files('libs/my_library.aar', "$rootDir/common/libs/other_library.aar")

By the way, there's a reasonably complete list of supported dependency types at https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html .

Cliabhach
  • 1,402
  • 2
  • 12
  • 19
2

After replacing .arr file through Windows explorer. The only thing that worked for me is File -> Invalidate caches / Restrt

Evgeniy
  • 509
  • 5
  • 14
0

Have you tried closing the tab of your decompiled file on Android Studio first, update the versionName on the AAR project, rebuild AAR, transfer, and then see it gets updated?

I know it works for me.

Arzath
  • 117
  • 1
  • 11
0

In addition to Commenting/Uncommenting & Re-sync Gradle project and settings, I had to delete the entire build-cache directory.

On Mac: ~/.android/build-cache/ Windows: Unsure of where this directory location is.

Alex Nguyen
  • 2,820
  • 1
  • 19
  • 14