Nikhil S. Teamcenter professional working with Siemens PLM Japan. at Geometric Ltd.
I have created an android project, for some of my
requirement I need to add some of external jars. I tried importing these files
from configure build path.
I do not get any error at comilation, but when
tried to run this apk in emulator, got class not found exception??
Any
one have solution for this ...?
thanking in advance..
22 comments Jump to most recent comment
Richard
Richard B.
Software Engineering Consultant
If you are using eclipse:
- Right click the
project
- Click on Properties
- Click on Java Build Path
- Select the
Libraries tab
- Click Add External Jars
- Find and select each .jar
file
- Click OK when done adding JARs
Preference
1. Java > Build Path > User Libraries
1. Click "New" and give a name in "User Library Name" field and click OK.
1. Select Library Name and click on "Add JARs" button.
5. Select JARs required to be used in your Android project and click OK." height="60" width="60">
Chrysa
Chrysa P.
Software Engineer at Intracom Telecom
In addition, to avoid adb message "Unable to execute dex:
Java heap space" , i recommend you to create a User Library and add jars to it :
1. Windows > Preference
2. Java > Build Path > User
Libraries
3. Click "New" and give a name in "User Library Name" field and
click OK.
4. Select Library Name and click on "Add JARs" button.
5.
Select JARs required to be used in your Android project and click OK.
Java Build Path > Libraries and remove all jar files except Android 2.2/4.0 and Android Dependacies." height="60" width="60">
Stephen
Stephen M.
Web Designer & Android App Developer
Since ADT 17 the process has changed. You need to copy the jar files into the 'libs' folder. Then go into your project Properties > Java Build Path > Libraries and remove all jar files except Android 2.2/4.0 and Android Dependacies.
Nikhil
Nikhil S.
Teamcenter professional working with Siemens PLM Japan. at Geometric Ltd.
Thank you all for your support.
Actually I am able
to add the jars successfully from eclipse, as mensioned by Chryssa Papadaki.
Also implemented them in my code. At the time of compile i found no errors,
means my jars are there.
But at run time I am getting the
exception(class not found.) I am using Android 2.3.3
Prakash
Prakash N.
Android Developer at Jawbone
You need to export them in "order and export" tab in Java Build Path.
"Configure Build Path" and then select "Source" > "Add Folder". Here tick the "libs" folder, then select "OK".
Then, run the program you wont get class not found exception." height="60" width="60">
Arshad
Arshad P.
Android Developer at Konstant Infosolutions Pvt. Ltd.
For removing run time exception(class not found) :-
First copy all the jar files into the '"libs'" folder. Then go to "Java
Build Path" > "Configure Build Path" and then select "Source" > "Add
Folder". Here tick the "libs" folder, then select "OK".
Then, run the
program you wont get class not found exception.
Prakash
Prakash N.
Android Developer at Jawbone
The OP is talking about adding external jars, i.e. no copying is involved.
configure build path----> libraries-----> if you see the added library then go to order and export. there you should select the added external library as well and close it. now again under the project click clean. now exit the eclipse. again restart eclipse and run the project. let me know if you have a problem." height="60" width="60">
Hari
Hari K.
Android developer at Mode fin server pvt ltd
just check the manifest file.... if everything is fine go to the eclipse. under the project click clean. now exit the eclipse. again restart and run it. again if you have a problem, Right click on whatever you are doing project, go to the build path---->configure build path----> libraries-----> if you see the added library then go to order and export. there you should select the added external library as well and close it. now again under the project click clean. now exit the eclipse. again restart eclipse and run the project. let me know if you have a problem.
Nikhil
Nikhil S.
Teamcenter professional working with Siemens PLM Japan. at Geometric Ltd.
Thank you Prashant Hari.
it really worked ..
But actually my external jar was using IOException from
"java.io"
And now i got stuck for this class .
Do we need to handle the
IOException class differently? Cause this package is a part of jre. As my
external jar is using this package/class I can not avoid its use / can not use
some Android ioexception classes.. if any.
Please help.
thanking in
advance.
Hari
Hari K.
Android developer at Mode fin server pvt ltd
no need to handle io exception class seperately...... you can write throws exception where it the ignores that exception
Library -> Add JAR should allow you to pick the one out of your project. IIRC, this works with Eclipse.
If you decide someday to dump Eclipse, just having your JAR in libs/ is enough -- the command-line build tools will pick it up automatically.
UPDATE: If you have the R17 or newer version of the ADT Eclipse plugin, now you only need to add a libs/ directory and put your JAR in there. It will automatically be added to your build path, much like with command-line builds." height="60" width="60">
pavan
pavan R.
student at RJS polytechnic at RJS POLYTECHNIC
Put the JAR in your project's libs/ directory. Then Build
Path -> Library -> Add JAR should allow you to pick the one out of your
project. IIRC, this works with Eclipse.
If you decide someday to dump
Eclipse, just having your JAR in libs/ is enough -- the command-line build tools
will pick it up automatically.
UPDATE: If you have the R17 or newer
version of the ADT Eclipse plugin, now you only need to add a libs/ directory
and put your JAR in there. It will automatically be added to your build path,
much like with command-line builds.
Tomasz
Tomasz C.
Software engineer at DC S.A.
How do you run your app? Is this some android virtual device?
properties-->java Build Path -->Libraries -->Add external Jars .it must be work..." height="60" width="60">
Thusitha
Thusitha W.
Software Engineer at Ascensor Partners(pvt)Ltd.
if You are using eclipse please follow like this..Right click your project folder -->properties-->java Build Path -->Libraries -->Add external Jars .it must be work...
John
John O.
Applications Designer at Riverside County Office of Education
http://stackoverflow.com/questions/2247998/noclassdeffounderror-eclipse-and-android/9916751#9916751
The
real problem here is that ADT isn't packaging the JAR files / libraries into the
.apk, so while the application builds properly, the NoClassDefFoundError occurs
when you're trying to run on the actual device.
Putting your .jar files
in the /libs directory is one way to ensure that your .JAR's get included in the
final .apk.
Dandre
Dandre A.
Android Developer for KeepandShare.com
You can manage project dependencies with a build tool like Maven or Ant.
Dandre
Dandre A.
Android Developer for KeepandShare.com
If proguard is making the apk it is sometimes necessary to tell it to not skip certain classes in the config file, because from its view the class is not used, when classes are used dynamically at runtime.
Java Build Path > Order and Export”, and check all the references you want exported."" height="60" width="60">
pasquale
pasquale O.
Product manager presso DotAndMedia S.r.l.
Hi All,
a good explanation/solution
of this problem in this post: http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
"If
you have references to jars that are not in the ‘libs’ folder, for example if
you use ‘classpath variable’, you can resolve the NoClassDefFoundError issue
with the new ADT 17 by exporting the references.
To export the
references: simply go to “Properties > Java Build Path > Order and
Export”, and check all the references you want exported."
Richard
Richard B.
Software Engineering Consultant
@pasquale, you are correct. I ran into this exact problem recently. I also discoverd that the order of export is important (though I can't imagine why). The external jars need to be at the top of the list.
Nikhil
Nikhil S.
Teamcenter professional working with Siemens PLM Japan. at Geometric Ltd.
Thank you all of you.
Copying in to "libs" folder
solved my problem.
thank you all of you once again.
Neeraj
Neeraj R.
software Engineer at Arion Infotech
just enter into your project path and create a folder and named it as 'Libs' then paste your all external jars into that folder.... thatz enough...
Afif
Afif N.
Android Developer at AppealSoft
it doesn't work at all.. my jar files are not getting open.. Whats the problem will????.
Neeraj
Neeraj R.
software Engineer at Arion Infotech
@ afif Nadaf.... which ide ur using.... in Netbeans i this method will work
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology