I am facing Error:java.lang.NoClassDefFoundError when importing a jar and using its classes.
This problem might be thought of a duplicate to this question. But I have a different condition:
I have prepared a .jar file from Eclipse SDK for Android .so it has folder such as /res /assets etc.
I have goggled for solution tried some of the solutions:
Build path-> Configure BuildPath->Add External jar
Copy .jar to /libs directory.
None of them worked!!!
P.S. In a previous project i have already used SQLCipher.jar file by just by adding it to the build path and have faced no problems.Though It had some filename.dat (which i have to add into /assets folder) and i have no idea what so ever if that has any role in accessing methods in the class of the jar.
I strongly recommend using Android Studio, the gradle build system is much easier than adding the libs manually. Just add compile 'net.sqlcipher:sqlcipher-gradle:3.0.1' to the build script, and the library will be downloaded and added with 1 mouse click.
Eclipse is missing powerfull features that Android Studio has
On toppic:
You need to import the jars from the build config dialog, click import external jar and select your jar
The library you added may need some external library eg google play services or something, do check that
Related
I'll start this off by saying that I'm not a Java dev, I work in a .NET software house, but somehow we have ended up needing to modify some legacy java code.
So I have a project which I've opened up with IntelliJ IDEA Ultimate 2016.2. As far as I can tell this doesn't use Maven or Gradle or any other dependency management tool, and as I have no idea what I'm doing with Java projects I'm not going to start trying to understand that now.
I'm trying to add the Amazon AWS SDK to my project so I can upload some files to an S3 bucket. I've downloaded the SDK from the AWS site, and extracted the jar files into the lib folder of my project root. I've tried numerous ways of adding these as dependencies, right click the jar files and add as library, go into settings, modules, dependencies, click the plus and add the jars etc. When I build the project it builds fine, and intellisense if picking up the classes and methods when writing the code to utilise the SDK.
However, as soon as I run the app, I get a "java.lang.NoClassDefFound" for the com/amazonaws/AmazonServiceException package as the containing class is instantiated.
This could well be something to do with the "CLASSPATH" that I hear so much about (but don't fully understand), but my understanding was that IntelliJ handled this when adding the jars as a dependency. I've also tried adding all the jars from the "third-party" directory from the downloaded AWS zip file, and adding those as dependencies as well, but it still doesn't want to work.
Incidentally, I'm adding the jars to the lib folder so they are included in source control.
Any suggestions on how to use the AWS SDK without using Maven or Gradle?
Cheers
What I've done is to manually add all the jar files into the External Libraries.
Go to File > Project Structure
In the left window pane, choose Modules under Project Settings
Click on the Dependencies tab
Click on the + sign and select 1 JARs or Directories
Navigate to the folders containing the jar files (include third-party dependecies also) and click OK
See My IntelliJ screenshot
I'm developing a RestFul services and I have my jar client that contains all my DTOs to communicate with the android application(client side). I can have reference to my jar client in the eclipse editor, but when I generate the APK and run the application in my emulator or my cellphone the class doesn't exist because the jar wasn't imported to the APK.
I test many things, adding the jars into the library and export them, also, I created a User Library and included all my jars into this and export that library, but neither of these work.
Anybody can help me please?
First of all, create a folder called "lib" inside your eclipse project and put all your jar files in that folder.
Then. go to:
Project->Properties->Java Build Path->Libraries
Just click into "Add JARs..." and select the jar files inside the lib folder.
Click and OK and Clean/Build your project
You will probably need to export the JAR file you are referencing if it hasn't already been added to the "Android Private Libraries" group in Eclipse.
I am trying to add a JAR to libs for another project and then use resources from the JAR inside of that project but I am getting
java.lang.NoClassDefFoundError: com.xxxxx.dylib.R$drawable.
The JAR contents are:
com.xxxxx.dylib
res
res.layout
res.menu
res.values
When the library project is added as a dependency it works but when the JAR is used there is no R.java generated. I believe this is the problem. Is it possible to use resources from a jar within a project?
Resources cannot be packaged into jar. Pure java class that do not refer to resources can be packaged into jars.
You need to make the project that you need to refer to as a library project and then refer the same in your android project.
http://developer.android.com/tools/projects/index.html
If you want to use command line
http://developer.android.com/tools/projects/projects-cmdline.html
If your using eclipse follow the below link.
http://developer.android.com/tools/projects/projects-eclipse.html
You can right click on the project that you want to refer, goto properties. Choose Android and check Is Library.
Now to refer the library project in your android project.
Right click on your android project, goto properties, choose android, click add browse the library project and the same.
JAR files package only the Java code you have, and not the resources.
If you want to use the resources in your project, you will have to take the entire library project, mark it as a library and then add it to your main project as a whole.
I am trying to use external jar file in android application. The jar file is running well in another java application but when I am trying to use the Jar file with Android Application by BuildPath-> Add External Jars; it is showing following errors
"could not find class referenced from method ".
Please help me out from this.
Thanks
Shorav
Maybe the ADK update has messed-up with your project's build-path. Try removing the JAR and add it again to your libs folder, and do a Clean Project.
following poster's comment about not having a libs folder:
You should try this:
Remove all references to the JAR in your project -> your code should not build without error anymore
Create à libs folder at the root of your project
Copy the JAR into the libs folder
(If still not running OK) Right click your project > Android Tools > Fix Project Propertie
If you want to use a Jar in android application you may create it like this:
Open your IDE
Click on new
Choose new Android project
Give the name of your project
Check option make this project as library
It seems like there are many different answers to this question, none of which work for me!
When I build my android app with eclipse, everything works fine. My JAR file is located in the /libs directory of my project, as recommended.
I am using SDK r15 (the latest android sdk available).
When I run ant debug, the apk file is built. However upon running the file in the emulator, a force quit is thrown. From LogCat, I see errors consistent with the JAR file not being compiled.
Many of the answers I see here, refer to older versions of the SDK. Also many refer to files which no longer exist. For example, android_rules.xml no longer exists in the ../tools/ant/ directory. Instead I see only a build.xml.
Has anyone solved this issue for the latest android.
Not I MUST use ant (not eclipse) for this build..
If you use ant to build your android project, just add your jar to the libs project. Eclipse will need you to add it through the project properties wizard. Maven should have some archteyp for that but I don't know it.
An extra jar file needs to be both added through dex and apkbuilder, that's not that easy to do it buy hand, you would be more confortable using ant tools coming with the android sdk, they are pretty well done and provide intersting features like adding jars, build a project for debug and release, testing,etc..
add your jar to a folder named libs and run ant compile from the project basedir.