3

I am trying to include a jar file in my apk file.

I tried the following:

    • copy the jar into lib directory in my project
    • add jar to path
    • enable the jar for export
    • simply add the jar to my project path (location anywhere else)
    • enable jar for export

But the apk does not include the jar. When I try to lanch the application the console tells me:

Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
Please check logcat output for more details.
Launch canceled!

I'm using

Eclipse IDE for Java Developers Version: Indigo Service Release 1 Build id: 20110916-0149
and
Android Development Toolkit Version: 16.0.1.v201112150204-238534

EDIT: This problem is solved. If I don't declare the libary as needed in the manifest it works. (Strange behaviour)

Henrik
  • 133
  • 1
  • 3
  • 9
  • does this answer your questions? http://stackoverflow.com/questions/1334802/how-can-i-use-external-jars-in-an-android-project – Stagleton Dec 28 '11 at 08:39
  • Are you using Google Maps API? – Cata Dec 28 '11 at 08:40
  • @ Stagleton: no, does not help. I think I had this post with google – Henrik Dec 28 '11 at 08:58
  • Yesterday we discussed some problems with the jar files in Android. Can you check this? http://stackoverflow.com/questions/8645442/android-class-not-found-from-imported-jar-file/8646185#comment10745783_8646185 – Yury Dec 28 '11 at 09:21
  • Can you also include in your question your manifest file? – Yury Dec 28 '11 at 09:23

9 Answers9

4

Make sure your .JAR is created with JavaSE-1.6, not 1.7

Nikhil
  • 16,194
  • 20
  • 64
  • 81
devkelly
  • 41
  • 2
  • This is what solved my problem! Never realized that it would not work, specially because Eclipse does not complain in anyway. Kudos for you buddy!!! – bruno.braga Jan 15 '13 at 04:20
  • 1
    This was my case aswell, thanks you very much for pointing out my oversight! I am considering opening a new question just to put a bigger spotlight on this solution. – ravemir Jun 23 '13 at 18:10
2

Not sure if you've resolved this, but I was having a similar problem and just adding the ".jar" file to the lib was not helping when I tried to run the app on the emulator.

What did finally allow me to make progress was to go through the same thing and add the library as described above, and then in the "Java Build Path" dialog, go to the "Order and Export" tab, and select the jar file there, too. Then the .apk was noticeably bigger, and the app got through the initial startup. (It still died afterward, but I think there is another permission problem there.)

I hope this helps?

Ken H.
  • 21
  • 2
1

For me, the following worked:

  1. Open .classpath file in project folder.
  2. Check it contains the row

    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    

    In my case, it was missing, so added it to the file.

  3. Restart Eclipse
biegleux
  • 13,179
  • 11
  • 45
  • 52
viskin
  • 493
  • 4
  • 15
1

Maybe you have tried this?:

Right click Project --> Properties --

  • Select Java Build Path
  • Make sure Libraries is the tab selected at the top
  • Click Add External JARs

Then find your JAR...you don't need it in your project.

TryTryAgain
  • 7,632
  • 11
  • 46
  • 82
  • 1
    May sound silly, but have you tried closing Eclipse, and/or cleaning the project? – TryTryAgain Dec 28 '11 at 08:55
  • Too bad, do you mind sharing what JAR you are adding? Is there a newer or even older version of that JAR you can try? – TryTryAgain Dec 28 '11 at 09:04
  • I compiled it myself --> [graphview](http://www.jjoe64.com/p/graphview-library.html) – Henrik Dec 28 '11 at 09:09
  • Is that completely necessary? ie: you made modifications? If not, I would suggest using the precompiled JAR https://github.com/downloads/jjoe64/GraphView/GraphView-2.0.jar and see if that works. – TryTryAgain Dec 28 '11 at 09:14
  • I copied it into the lib folder of my project, added it to path and enabled export --> same issue – Henrik Dec 28 '11 at 09:18
  • Hmmm, I added it fine: I did not make a lib folder, I just right clicked project --> Java Build Path --> Add External JARs and that worked. Maybe try doing that (nothing more nothing less) with a fresh project so we can rule out eclipse and start focusing on your project...report back. – TryTryAgain Dec 28 '11 at 09:22
  • Maybe, you should ask a new question or edit this one considerably. – TryTryAgain Dec 28 '11 at 10:51
0

Maybe it has changed in newer versions, but what I had to do was to add the jar as normal to be able to compile, then make sure that my jar file also is checked in the order and export tab of the Java Build Path settings.

HalfAsleep
  • 93
  • 1
  • 4
0

Right click on project --> Properties --> Java BuildPath --> Add External JARs.

and select jar what do you want add. click Ok..

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
0

if you are trying to add a jar file to your android application simply it's like this

create lib folder and copy the .jar file

In Eclipse, right click on your existing project, then choose properties. There will be a pop up window.(Right Click on Project Properties).

Arrow In that, select Java Build Path and then click on Libraries Tab, Here click on Add External Jar's button and then browse your jar file(in the lib folder) and select ok.

Hassy31
  • 2,793
  • 3
  • 21
  • 37
0

1) Create a lib folder in your project and copy the jar files in it. 2) Now in Eclipse right click your project and select properties 3) Properties--> java build path--> Libraries--> Add Jars. 4) In the add jars you can able to find out your jar files 5) Add the jar files one by one

BobDroid
  • 1,898
  • 5
  • 19
  • 39
0

create one folder in your application and paste jar file in that folder. After that go to java build path then select jar file from your application jar folder and click ok, I think your problem should be resolve. If you have any issue let me know.

Manoj Kumar
  • 587
  • 2
  • 9
  • 20