22

I've spent hours trying to get a library to work with my project in Android Studio, and I just can't figure it out.

Here's what my dependencies look like for my module enter image description here

And my libraries: http://i.imgur.com/t8E3sB8.png

I've even added

compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-core-1.2.1.2.jar')

to my build.gradle. Without this, the app would not even compile.

At this stage, when I try to reference one of the libraries in code, the app crashes with a NoClassDefFoundError exception.

Something tells me this shouldn't be this hard - what am I overlooking?

LogCat:

05-17 21:51:15.676: I/ActivityManager(714): START u0 {flg=0x10104000 cmp=com.crazydog.splitwiser/.InitialSplash bnds=[328,402][656,692]} from pid 1513
05-17 21:51:15.896: I/ActivityManager(714): Start proc com.crazydog.splitwiser for activity com.crazydog.splitwiser/.InitialSplash: pid=18174 uid=10288 gids={50288, 3003, 1028}
05-17 21:51:16.326: I/ActivityManager(714): Displayed com.crazydog.splitwiser/.InitialSplash: +437ms (total +1m9s209ms)
05-17 21:51:17.017: I/ActivityManager(714): START u0 {cmp=com.crazydog.splitwiser/.LogIn} from pid 18174
05-17 21:51:17.097: E/dalvikvm(18174): Could not find class 'oauth.signpost.commonshttp.CommonsHttpOAuthConsumer', referenced from method com.crazydog.splitwiser.Toolkit.oAuthTransaction
05-17 21:51:17.097: W/dalvikvm(18174): VFY: unable to resolve new-instance 662 (Loauth/signpost/commonshttp/CommonsHttpOAuthConsumer;) in Lcom/crazydog/splitwiser/Toolkit;
05-17 21:51:17.097: D/dalvikvm(18174): DexOpt: unable to opt direct call 0x112f at 0x08 in Lcom/crazydog/splitwiser/Toolkit;.oAuthTransaction
05-17 21:51:17.107: E/AndroidRuntime(18174):    at com.crazydog.splitwiser.Toolkit.oAuthTransaction(Toolkit.java:65)
05-17 21:51:17.107: E/AndroidRuntime(18174):    at com.crazydog.splitwiser.LogIn.onResume(LogIn.java:116)
05-17 21:51:17.117: W/ActivityManager(714):   Force finishing activity com.crazydog.splitwiser/.LogIn
05-17 21:51:17.117: W/ActivityManager(714):   Force finishing activity com.crazydog.splitwiser/.InitialSplash
05-17 21:51:17.618: W/ActivityManager(714): Activity pause timeout for ActivityRecord{40d040d0 u0 com.crazydog.splitwiser/.LogIn}
Jonah H.
  • 1,760
  • 4
  • 18
  • 31
  • I added it to the post. – Jonah H. May 18 '13 at 04:52
  • does core rely on http? – Blundell May 18 '13 at 04:54
  • I think you have imported wrong class. Please check the import statements at the top of the code – moDev May 18 '13 at 04:55
  • Line 7 of Toolkit.java: import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; – Jonah H. May 18 '13 at 04:57
  • @Blundell: No - the core library does not rely on the commonshttp library, if that's what you mean. commonshttp may rely on core. – Jonah H. May 18 '13 at 05:02
  • I think the problem is you haven't declared that http rely's on core then – Blundell May 18 '13 at 05:32
  • Alright...how would I do that? – Jonah H. May 18 '13 at 05:56
  • I'm running into a similar issue - I think it's related to the runtime configuration on the build.gradle, but I get stuck there. Seems like you have to define explicit runtime and compile time dependencies. – daviddeath May 18 '13 at 07:55
  • Why do you have two modules? Does one depend on the other as and android library project? If so you have to add the Module dependency with the + icon on the right of the Module dependency configuration window. see http://stackoverflow.com/questions/16622410/how-do-i-add-a-library-project-to-the-android-studio-and-use-itsome-asked-dont/16623632#16623632 – Thibault D. May 18 '13 at 11:18
  • Why do I have two modules? You know as well as me. That seems to be how the project was created inside of Android Studio. – Jonah H. May 18 '13 at 18:21
  • @thibaultd: Just for sanity checking, I created a brand new project, and it had two modules. In my original project, I cannot add the outer module as a dependency of the inner module, as when I do that, I get an error about package names being the same. – Jonah H. May 18 '13 at 18:34
  • Yeah I've seen that on another Question, I can't guess why it's so. Whether it's a bug or a feature. – Thibault D. May 18 '13 at 19:11

1 Answers1

29

I had the exact same problem, And like you i thought it's enough to add the

compile files('libs/signpost-commonshttp4-1.2.1.2.jar')
compile files('libs/signpost-core-1.2.1.2.jar')

It all worked after i did a ./gradlew clean (I'm on a mac, so in your case, the equivalent.) You should do this command from the Terminal/Command prompt when you're located on the root of your project.

Dany Y
  • 6,833
  • 6
  • 46
  • 83