I am working on an app which uses Commonslang.jar libraries. I was trying to setup it on a new system with newly installed Eclipse.The project is not showing any error But when I run the project it force closes with NoClassDefFoundError at each point where I use Commonslang lib.
I dont know how to fix this problem.Please help?
I think there are "lib" folder in your project directory so just change it "libs" instead of "lib" and clean project and check it..
> Note: No need to build path for any third party library
You need to create libs folder in your project and copy that jar file there. Then in eclipse, right-click on that jar file (which is in libs folder) select Build Path and then select Add to Build Path.
Remember: if you are using a jar file in your Android Library Project, and associating that library project with your regular UI
project, it won't be enough. You must need to include that jar file
(as described above) in both of your projects (Android Library and UI
project) to make it work.
Have you added the jar to the Java Build Path?
Go to the Properties for the Project and select Java Build Path -> Libraries tab then add the external jar there.
Related
I imported an Android project into Eclipse (Custom ADT). During the import process, I chose to copy project into Workspace.
My project could compile and run well but after sometime, it stopped working. When I check in the 'Problems' View, I see that it still looks for the BIN folder in the folder from which the project was imported and it can't find the library it wants to reference.
Aren't Libraries copied along with the project in Android? How do I fix this?
A good way to add external JARs to your Android project or any Java project is:
Create a folder called libs in your project's root folder - you already had this
Copy your JAR files to the libs folder
Now right click on the Jar file and then select Build Path > Add to Build
Path, which will create a folder called 'Referenced Libraries' within your
project
By doing this, you will not
lose your libraries that are being referenced on your
hard drive whenever you transfer your project to another computer.
You need to place the Libraries into your libs folder before you copy/import. Because if you just added the Library over the Build-path its just copy the Reference, not the Library itself.
I want to use a svg-android library to work with *.svg files in Android. For the same, I've installed the apache ant, created a folder in workspace called: SVGAndroid and then added
android.library.reference.1=C:\Android\workspace\SVGAndroid
to project.properties file.
There were no documentation for functions in ReadMe, so I'm wondering if the installation correct or not, how to reinstall an external lib in the second case and where are the examples of using svg-android?
For your including of the project, just include the project into your workspace and in your respective application under the properties of that project just add a dependency on a library that references svgandroid. Make SURE to include the files and ensure that the compile class files are present in the final output of the apk. This typically means that you add the project to your build path/order.
Another approach is to just take the entire project and compile it into a jar file and then include that jar in your libs folder and add that dependency on the jar file of that respective project to your core application.
Useful links
How can I use external JARs in an Android project?
I would rather suggest to not add the path to the project manually, but from Project Properties -> Android and you will have a list with all the library projects in the workspace from which you can choose the desired project.
Also I suggest adding in project.properties the following line:
manifestmerger.enabled=true
in order to have all the AndroidManifest.xml files of the referenced library projects merged into the main project's manifest.
If you want to include a library file in to your project follow the below steps;
Download a jar file and save it in any folder.
open your project.
Right click--> Build path--> Add External Archives---> Add your external jar file to your project
I'm trying to use an external jar file in my Android project, I follwed this step for including it:
I put the jar file in libs.
I configured the build path and now I can see the jar file in the Referenced Libraries section of the project.
I use the import to bring the class that I need inside the program.
But I always get NoClassDefFoundError. This jar already works with a classic java program.
Make sure that the jar is being built with the app. In eclipse,
right click on project --> build path --> configure build path.
Make sure the library is checked in the Order and Export tab.
Since Android SDK 17 there is not even necessary to manually add the jar files to buildpath, because they are added automatically, as stated here. Then I would suggest to:
remove the library from buildpath
clean the project
make sure the jar file is located in a folder called libs (not lib) located in the root folder of your project
refresh the project
run the project
The solution found was recompile the library with the version 6 of java and using the jar fail obtained
I have made an android project in eclipse. This project has a library project:
the library project (marked with "is library") has included a jar file.
this library project does a lot of stuff with the use of the jar file.
in code everything is fine.
The problem is that the reference to the jar file doesn't exist anymore when it is compiled and installed to my phone.
When i add the jarfile also to my base project. Then the program works.
However, i don't believe that this is the right solution.
So what does i do wrong?
You should add a libs folder to your project
Then, add the jar to the folder and right click on the .jar file and go to Build Path, and select Add To Path or Build To Path. This way the library will be a part of your project. This should help.
The library jar you used in your Android Library Project must be manually added to the dependent application project's build path, not the Android library project build path itself, check out API here
I am going to create a library project which has several dependencies (jar files).
I am confused because I've seen some android projects which has LIB or LIBS folder under project root folder (together with bin,gen,res,src.etc..)
Even I add LIB or LIBS folder, then put the jar files on it. Still need to set the project properties in order to recognize the added jar files by doing Project Properties => Java Build Path => Libraries tab => Add JARs... button.
I am using Eclipse with Android Plugin.
When I add LIBS, it will appear the Android logo on the top of the LIBS folder. It is recognized by the plugin but still need to set it in the project properties (same the above adding JARs)
Which is the correct directory structure for Android Project?
If you use the Android command line to create your project, it'll default to libs/. It turns out that the Android Ant tasks are set to look in libs/ by default.
See $ANDROID_HOME/tools/ant/main_rules.xml:
<property name="jar.libs.dir" value="libs" />
If you just care about Eclipse, you can use whatever you want.
In newer revisions of ADT (revision 17 onwards), the Ant-based build system and the Eclipse plug-in are aligned so that they behave the same way. This means, by default, only the jars that are present in the libs folder are included in the final apk file. These jars would automatically appear under "Android Dependencies" in your Eclipse project.
For more details please refer here. http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
It doesn't matter actually. It can be lib or libs. Whether jar files are in lib or in libs, you just need to do right click on project, select "Build path => Add to build path" , thats it.
Citing: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
If you are still referencing jar libraries manually instead of putting them under libs/ be aware of the following:
If the project is a Library project, these jar libraries will not be automatically visible to application projects. You should really move these to libs/
If the project is an application, this can work but you must make sure to mark the jar files as exported.