0

I'm building a library project in which I'm using 3rd party jar file.

Normally when I use the library as a dependency on TestApp all things works as it should. Attached is the screenshot for that:

Library project dependency which worked

But, when I export jar from the TestSDK library project and add it to the build path of the TestApp, which looks like this:

Added jar to build path

Full view of order and export

I get VerifyError when deploying the app on device. Below are the logs for it:

12-30 18:10:55.778: W/dalvikvm(7316): VFY: unable to find class referenced in signature (Lcom/aerserv/sdk/ASAdView;)
12-30 18:10:55.788: W/dalvikvm(7316): VFY: Ljava/lang/Object; is not instance of Landroid/view/View;
12-30 18:10:55.788: W/dalvikvm(7316): VFY: bad arg 1 (into Landroid/view/View;)
12-30 18:10:55.788: W/dalvikvm(7316): VFY:  rejecting call to Landroid/view/ViewGroup;.removeView (Landroid/view/View;)V
12-30 18:10:55.788: W/dalvikvm(7316): VFY:  rejecting opcode 0x6e at 0x0011
12-30 18:10:55.788: W/dalvikvm(7316): VFY:  rejected Lcom/anupam/sdk/activities/AdsActivity;.initAerservAd ()V
12-30 18:10:55.788: W/dalvikvm(7316): Verifier rejected class Lcom/anupam/sdk/activities/AdsActivity;
12-30 18:10:55.788: W/dalvikvm(7316): Class init failed in newInstance call (Lcom/anupam/sdk/activities/AdsActivity;)
12-30 18:10:55.788: D/AndroidRuntime(7316): Shutting down VM
12-30 18:10:55.788: W/dalvikvm(7316): threadid=1: thread exiting with uncaught exception (group=0x41596ba8)
12-30 18:10:55.788: E/AndroidRuntime(7316): FATAL EXCEPTION: main
12-30 18:10:55.788: E/AndroidRuntime(7316): Process: com.anupam.testsdk, PID: 7316
12-30 18:10:55.788: E/AndroidRuntime(7316): java.lang.VerifyError: com/anupam/sdk/activities/AdsActivity

What should be the correct way to do that? Am I missing something here. Any kind of help or guidance will be much appreciated.

Anupam
  • 3,742
  • 18
  • 55
  • 87

1 Answers1

2

I think your JAR depends on Aerserv SDK but does not include it. And I don't see it being included in the app either.

Please note that build dependencies of your JAR library will not automatically get included. Dependencies are an issue when building libraries. You have two options: include the dependencies in the jar itself (you have to force your build system to do that) or instruct the library user to do that (similar to how Aerserv does it). When including dependencies you risk conflict if library user ads them too.

atok
  • 5,880
  • 3
  • 33
  • 62
  • So, manually I'll have to aerserv jar in the TestApp, can't it be included in library project itself? – Anupam Dec 30 '14 at 13:30
  • Thanks atok for the real quick answer. Please correct me if I'm wrong. To get this to work, I'll have to manually add aerserv source code in the library project instead of a jar? Or secondly I'll have to add aerserv jar manually in my TestApp to work? Other than this nothing can be done for solving this issue? – Anupam Dec 30 '14 at 13:42
  • Copying code is a bad idea because you loose track of changes in your dependencies. You can build a "fat jar" with all dependencies included automatically using Gradle or Maven. – atok Dec 30 '14 at 13:46
  • Can you guide me how to do that? I have never used Gradle or Maven for this purpose. I have heard about oneJar concept, but I doubt that will work for me. Do you recommend something else for this? – Anupam Dec 30 '14 at 13:48
  • @Anupam are you using eclipse? – Yazan Dec 30 '14 at 14:00
  • Yes @Yazan I'm on eclipse. – Anupam Dec 30 '14 at 14:01
  • if those screenshots are yours, at your library project, go to the tab ,`Order and Export` next to libraries, you will find that 3rd party jar, check the option near it (checkbox) and then export your library as jar, this should include the 3rd party jar in your jar, 2 in 1, then including your jar will be sufficient for the TestApp – Yazan Dec 30 '14 at 14:03
  • @Yazan Yes those are my screenshots, but on order and export I could not see the third party jar option there. Can you provide me the exact process for it. – Anupam Dec 30 '14 at 14:48
  • @Anupam not in your testApp, but in your library project, that if you added it from calsspath, if you added it in libs folder, you will not see it there – Yazan Dec 30 '14 at 14:59
  • @Yazan Have attached the full view of my TestSDK properties window. I can't see the feature what you are mentioning. – Anupam Dec 30 '14 at 15:09
  • @Anupam it looks you are adding the 3rd party jar file in /libs folder, not using classpath, it might appear in `android private libraries` section, so -if this is the case- and in order to be able to include it, remove it from /libs and add it to classpath (add external JAR), then you will find it – Yazan Dec 30 '14 at 15:24
  • @atok Have referenced http://www.mkyong.com/maven/maven-create-a-fat-jar-file-one-jar-example/, after completing all the steps. The dependency issue is not resolved. Can you guide me here? – Anupam Jan 28 '15 at 11:34