How to include this library https://github.com/jdamcd/android-crop to my existing android project?
Tried to import it via "Existing Projects into Workspace" and "File System" but I was unable to use the classes of the library.
That project is designed to be built by Gradle (and, by extension, Android Studio). The directory structure of the lib/ project is not set up in the legacy project structure used by Eclipse or Ant.
You would have to create your own Android library project, then:
Copy over the manifest into your library project
Copy over the res/ directory into your library project
Copy over the java/ directory into your library project as the src/ directory in your project
Then, in principle, you should be able to add your own edition of the library project to your app.
i have a requirement like i have to use one app for two other applications. so i want to create a library project as jar file so that i can use that in build path easily with out adding the project. so i have added my main project as a library project so it has generated jar file in bin folder . so i have copied that jar file and added to libs and added that to my project build path. but still i am getting no class def found exception. please sugest whether this process of generating a jar file is correct or not. if it is not correct please suggest me how to do.
Rightclick on the library project, export -> Jar file.
Select all files, except the AndroidManifest.xml.
Make sure you DON'T select manifest file. Else it will lead to conflict errors.
Now include this JAR file in the build path, and it will work. I did the same.
Let me know if you have any issues.
The Most Important thing , your project doesn't contain any Resources (RES folder) then
1- Right Click on Project –> Export —> Java –> JarFile
2-Select only the src checkbox ie the (pacakages) in Top-Left Window.
Don’t Select anything in Top-Right Window if some thing is selected remove marks .
3-Select Only Export generates Class Files and Resources
4-In Options Select only Compress the contents of the jar file (it's not important)
To add your External Jar to Your File
1-Right click on project –> Select Properties –> Java Build Path —> libraries –> Add External Jar Files –> Click OK
2-CLEAN your Project
You can export your project as a jar.To do this
right click your project->export->java->JAR file->Next
But if you use resources in the library project then you won't get it from the jar.But it will be available if you use as a library project rather than jar
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
Source
You need to do following:
Add reference of .jar file to your client application. Right click project -> properties -> Click 'Java Build Path' -> open Libraries tab -> Click button 'Add External JARs..' and select the .Jar file that you have created -> Go to 'Order and Export' tab and select the Added external Jar and move it to the top.
I hope this will help you.
Mark +1 if it is helpful to you.
I want to parse a html file, and i found Jsoup in google
and i download Jsoup-1.6.3.jar
then i create a file in my project root named libs
in eclipse -> RIGHT_CLICK the project -> properties -> Libraries -> add jars
-> choose Jsoup.jar in folder libs -> ok
but when i click Jsoup.jar in Libraries, i found that:
Source attachment(None), Javadoc location(None), Native library location(None)
did i lose any step?
Can someone teach me how to import Jsoup in project?
You can try:
Create a folder "libs"
Add your jar into libs folder
Right click on jars and select Build Path -> Add to build path., it will create a "Referenced Library" folder in your project structure.
Copy or move your Jsoup-1.6.3.jar into your project source then right click on the Jsoup-1.6.3.jar, Build path and add to Build path. Done your're good to go!
I saw an article about including additional javax.* packages in your Android App
http://code.google.com/p/dalvik/wiki/JavaxPackages.
I wanted to do the same thing, but using Eclipse.
Could anyone help me figure out how to do this?
Step 1: Properties -> Java Build Path -> Libraries -> add external jar
Step 2: Properties -> Java Build Path -> Order and Export -> check the new lib
Adding an External Library (.jar) using Eclipse
You can use a third party JAR in your application by adding it to your Eclipse project as follows:
In the Package Explorer panel, right-click on your project and select Properties.
Select Java Build Path, then the tab Libraries.
Press the Add External JARs... button and select the JAR file.
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead. It is not necessary to put external JARs in the assets folder.
I have created an Android project and added an external JAR (hessian-4.0.1.jar) to my project. I then added the JAR to the build path and checked it off in Order and Export.
Order and Export is ignored it seems, and all classes from the external JAR are missing at runtime.
Is there a trick to properly include the needed classes from an external JAR when building an Android application using the Eclipse plugin? I do not want to use ant or Maven.
For Eclipse
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
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.
For Android Studio
If you are in Android View in project explorer, change it to Project view as below
Right click the desired module where you would like to add the external library, then select New > Directroy and name it as 'libs'
Now copy the blah_blah.jar into the 'libs' folder
Right click the blah_blah.jar, Then select 'Add as Library..'. This will automatically add and entry in build.gradle as compile files('libs/blah_blah.jar') and sync the gradle. And you are done
Please Note : If you are using 3rd party libraries then it is better to use transitive dependencies where Gradle script automatically downloads the JAR and the dependency JAR when gradle script run.
Ex : compile 'com.google.android.gms:play-services-ads:9.4.0'
Read more about Gradle Dependency Mangement
Yes, you can use it. Here is how:
Your Project -> right click -> Import -> File System -> yourjar.jar
Your Project -> right click -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
This video might be useful in case you are having some issues.
I know the OP ends his question with reference to the Eclipse plugin, but I arrived here with a search that didn't specify Eclipse. So here goes for Android Studio:
Add jar file to libs directory (such as copy/paste)
Right-Click on jar file and select "Add as Library..."
click "Ok" on next dialog or renamed if you choose to.
That's it!
I'm currently using SDK 20.0.3 and none of the previous solutions worked for me.
The reason that hessdroid works where hess failed is because the two jar files contain java that is compiled for different virtual machines. The byte code created by the Java compiler is not guaranteed to run on the Dalvik virtual machine. The byte code created by the Android compiler is not guaranteed to run on the Java virtual machine.
In my case I had access to the source code and was able to create an Android jar file for it using the method that I described here: https://stackoverflow.com/a/13144382/545064
Turns out I have not looked good enough at my stack trace, the problem is not that the external JAR is not included.
The problem is that Android platform is missing javax.naming.* and many other packages that the external JAR has dependencies too.
Adding external JAR files, and setting Order and Export in Eclipse works as expected with Android projects.
Goto Current Project
RightClick->Properties->Java Build Path->Add Jar Files into Libraries -> Click OK
Then it is added into the Referenced Libraries File in your Current Project .
Android's Java API does not support javax.naming.* and many other javax.* stuff. You need to include the dependencies as separate jars.
If using Android Studio, do the following (I've copied and modified #Vinayak Bs answer):
Select the Project view in the Project sideview (instead of Packages or Android)
Create a folder called libs in your project's root folder
Copy your JAR files to the libs folder
The sideview will be updated and the JAR files will show up in your project
Now right click on each JAR file you want to import and then select "Add as Library...", which will include it in your project
After that, all you need to do is reference the new classes in your code, eg. import javax.mail.*
in android studio if using gradle
add this to build.gradle
compile fileTree(dir: 'libs', include: ['*.jar'])
and add the jar file to libs folder
If you are using gradle build system, follow these steps:
put jar files inside respective libs folder of your android app. You will generally find it at Project > app > libs. If libs folder is missing, create one.
add this to your build.gradle file your app. (Not to your Project's build.gradle)
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// other dependencies
}
This will include all your jar files available in libs folder.
If don't want to include all jar files, then you can add it individually.
compile fileTree(dir: 'libs', include: 'file.jar')
create a folder (like lib) inside your project, copy your jar to that folder.
now go to configure build path from right click on project, there in build path select
'add jar' browse to the folder you created and pick the jar.
Copying the .jar file into the Android project's folder isn't always possible.
Especially if it's an output of another project in your workspace, and it keeps getting updated.
To solve this you'll have to add the jar as a linked file to your project, instead of importing it (which will copy it locally).
In the UI choose:
Project -> Import -> File System -> yourjar.jar -> (Options area) Advanced -> Create link in workspace.
The link is save in the .project file:
<linkedResources>
<link>
<name>yourjar.jar</name>
<type>1</type>
<locationURI>PARENT-5-PROJECT_LOC/bin/android_ndk10d_armeabi-v7a/yourjar.jar</locationURI>
</link>
</linkedResources>
PARENT-5-PROJECT_LOC means relative to the project file, 5 directories up (../../../../../).
Then add it to the libraries:
Project -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
In the same window choose the Order and Export tab and mark your jar so it will be added to the apk.