3

I added the following dependency to to build.gradle file in Android Studio and resync-ed the project successfully:

compile 'se.emilsjolander:stickylistheaders:2.1.3'

However I was unable to use any of the class in this library. Feeling strange I opened the source tree and see if there's anything wrong. I noticed the following:

Empty classes.jar

You can see Android Studio can found the available classes for other downloaded archives, but not the one I mentioned in this question. The classes.jar file is reported empty.

I tried adding an older version of the stickylistheaders library (2.1.3). Still an empty classes.jar.

When I start this question I found a similar post here. But the author of that post tried to include the downloaded project in settings.gradle, and he finally managed to include the library through the "compile" directive. My problem is that I AM using the "compile" directive, but the downloaded archive has a "empty" classes.jar. I also tried adding the library mentioned in that question (i.e. 'se.emilsjolander:StickyScrollViewItems:1.0.0'). Also an empty classes.jar.

Some notes:

  • The actual classes.jar file found in build/exploded-bundles is not empty.
  • I tried cleaning the project. I suppose this will cause all dependencies be removed and re-downloaded. However, after that, Android Studio still cannot spot any class in stickylistheaders' classes.jar.
  • So far, this problem only exists for se.emilsjolander's libraries. Strangely, the answerer of this post1 posted a screenshot showing that he does see a non-empty classes.jar.

Update:

  • I also tried deleting .gradle's cache directory in my profile directory, clean the project and rebuild again. No luck.
  • I can unzip the classes.jar in question. Looks like the file isn't corrupt.

Anyone knows what's wrong here? Thanks.

Community
  • 1
  • 1
Edmund Tam
  • 868
  • 3
  • 7
  • 18

3 Answers3

2

I think I have found the cause: it should be a bug in Android Studio.

https://code.google.com/p/android/issues/detail?id=64008

In fact, the code can build and run despite seeing errors in Android Studio. So it is obviously an issue with Android Studio.

Update 27 Jan: It should have been resolved in Android 0.4.3. As from the release notes:

Fixed a bug around library syncing (where library dependency classes and resources could suddenly not be found by the IDE)

Edmund Tam
  • 868
  • 3
  • 7
  • 18
0

Have you tried syncing your project with Gradle?

Tools -> Android -> Sync project with Gradle Files. That should reload the build.gradle file and download the (missing) dependencies.

fifarunnerr
  • 617
  • 4
  • 12
  • Yes, as I mentioned, I have resync-ed the project successfully. To clarify, it is not the dependency missing. The library is there. Please check the screenshot. My question is about that "empty" classes.jar which prevent me from using the library. – Edmund Tam Jan 15 '14 at 12:26
  • Try removing the Gradle Dependency cache, as mentioned in this thread: http://stackoverflow.com/questions/13565082/how-can-i-force-gradle-to-redownload-dependencies It looks like Gradle failed to correctly download the library. – fifarunnerr Jan 15 '14 at 12:35
  • What version of Android Studio and Gradle are you using? – fifarunnerr Jan 15 '14 at 12:43
  • Android Studio 0.4.2, Gradle 1.9. BTW, I suspect my question is related to this bug: https://code.google.com/p/android/issues/detail?id=64008. However it is said that the fix is merged in 0.4.2, which doesn't seem to be the case. – Edmund Tam Jan 15 '14 at 12:49
  • It should be in 0.4.3. – Scott Barta Jan 15 '14 at 16:38
0

Try this once and make sure you are not getting any error in project Structure saying that "your_lib_name not used/added"

Open File > Project Structure 

and check for erros. If error is shown click on it , it will expend the errors and will show some options on right, click on the Red bulb and choose "Add to dependency".

erros

This seems be a bug in Studio which will be fixed in next release(Android Studio 0.4.3).

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • Thanks, but interestintly I don't have the "unused dependency" message after reimporting the project. – Edmund Tam Jan 16 '14 at 08:55
  • It can happen again when you sync your project with gradle.Its a bug and is solved for next release(0.4.3) as mentioned by @Scott Barta in above comments. – Piyush Agarwal Jan 16 '14 at 09:06