I want to create a jar file from one android project for another android project.I want select only certain classes not all classes from project.I tried eclipse-export way to create a jar.Jar file is created and it also contains all selected class files,after adding the created jar file to the main android project it gives the error:“java.lang.NoClassDefFoundError”.Is the eclipse-export way is not valid to create jar for android project?
I also tried steps provided by this blog http://www.olivacorner.com/2011/04/create-an-android-jar-library-with-eclipse/comment-page-1/#comment-343,but not able to create a desired jar file.
Can anybody please provide the steps to create a jar file for android project.
Thanks.
So you want to create a library for Android? In this case, you can create a Library-project and then reference to it in the main-project.
See the docs.
Step 1. Create Android library project as explained here.(Same as suggested by Lukas)
Step 2. Now you need to give reference of Android Library project created in step 1 to your client application. There are two ways to do so.
Give reference of Android Library Project itself by client app property -> Select 'Android' on left pane -> In Libraty Section, Add Android Libraty project (This is explained at link given in Step 1 above)
Give the reference of .jar file of Android Library project (from Location of Android Library project -> bin -> .jar file). Client Application -> Properties -> Click 'Java Build Path' in lefe pane -> Go to 'Libraries' Tab -> Click 'Add External JARs' button and select the .jar file -> Go to 'Order and Export' tab and select the added .jar file reference and move it to top.
Hope this will help you.
Related
I am new to Eclipse and I could not solve this problem.
How could I import this library to Eclipse using the default builder (not using Gradle)?
Without using Gradle/Maven and using Eclipse you need to manually add the library.
The library is in the jcenter repository, which means there is a jar file available. This jar file can be found here (I'm pretty sure you need the -sources.jar)
Download this library and save it in a logical place. Go to Eclipse, highlight the project and press Alt+Enter. Go to the Java Build Path page and click Add External JARs under the Libraries tab. Select the JAR file and it should be fine.
Keep in mind that the Eclipse ADT plugin is not the way Google wants you to do it. If you have no reason to use Eclipse other than that it's what you have set up now, you should probably move to Android Studio.
Create a new project and add github version project files to newly created project else download the entire project from github and add this project to your current project.
right click(current project) -> Build path -> Configure build path -> Java build path -> Projects (tab) -> click add
Just add this project there and build your project.
i've been struggling with this issue for a couple of days now...
ill explain my problem in a nutshell....
i have a simple java project (not android library or something more complex) which i want to use as my model..
lets assum it is called mymodel and it has a simple class Model.
i also have an android application myandroidapp and in the main activity i want to create an instance of the class Model.
I can add the mymodel as a project to the build path and compile but when i run this application it throws class not found exception. how can i make it work?
please help.
thanks
Step #1: Create a JAR based on your "simple java project"
Step #2: Put the JAR in the libs/ directory of your Android project
And you're done.
Never mess with the build path of an Android Eclipse project manually.
In Eclipse, you can follow the following steps:
Creating JAR file
Right-click on the root of the mymodel project and click on 'Export...'
In the window that appears, expand the 'Java' category/folder, choose 'JAR file' and click 'Next'
In the next window, choose the options you desire, especially pay attention to where the 'export destination' is. When you're done, click on 'Finish'. The JAR file will now be located at the 'export destination'.
Adding JAR to Android project
In your android project (myandroidapp), copy the JAR file into the libs/ folder. You can do this by simply copy and pasting or dragging and dropping etc.
Then, right-click on the JAR file that is now in the libs folder, go on 'Build Path' and from the menu that appears, click on 'Add to Build Path'
You should now be able to use this JAR file in your Android project.
I'm new to android and java. I downloaded the GSON library for use in my android project which exists in Eclipse. I lookup instructions on how to use the jar file in my project and it says...
Quote...
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
...UnQuote
I'm afraid that I don't know the difference between "using a 3rd party jar in my project" and "include third party jars with my package." I want to be able to use the GSON methods in my Android phone application and, of course, have the capability deployed in my .apk.
So, Which do I want to do?
Thanks, Gary
add the jar to your libs folder in your project.
open eclipse go to package explorer
right click on your project and select project properties
click on java Build path in the bar on the left hand side of the popup
select the libraries tab
select the "Add External Jar File" and navigate to your JAR file
best of luck =)
click Properties
left select Build path
Than add jar, and do not use the external libs, unless it is really required.
You have to copy the jar to your project to find it with "Add jars"
Right click onto your main project in the Project Explorer
Open properties option, found at the bottom of the context menu
A dialog box opens from which you select the Android option
Remove the old .jar file, click on ADD to add a new .jar file and select your the file you want to add
You're done!
Hi i have the project developed in eclipse environment is working fine, and i want to use that project as resource or add as jar file to another project.if possible can please let me know how to do this one. will help lot for me.
You can do it via Android Library project.
Refer this LINK.
Describes how to set up a project as a library project. Quoted from its content
================= quoted =================== Next, set the project's Properties to indicate that it is a library project:
1) In the Package Explorer, right-click the library project and select Properties.
2) In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
3) Select the "is Library" checkbox and click Apply.
4) Click OK to close the Properties window.
=============== unquoted =============================
So, you open your project properties and "unselect" "is Library" checkbox and click Apply to make your project a normal Android project (not a library project).
In theory you can as #Agarwal described.
however the adt-tools are not ready to do it yet
My last failed try was adt-tools version R17 documented at how-to-consume-reusable-gui-element-widget-with-resources-in-android
According to user #CommonsWare R18 and R19 still cannot do it (see comment in replace-android-library-project-by-jar-library )
I have an API in the form of a JAR that I would like to use in my Android app. Not sure if it should be part of the project in Eclipse or kept separate and added to the project properties. This JAR also needs to be packaged with the application, so how is that done for Android apps?
As explained by this SO question:
Your Project -> right click -> Import -> Archive File -> yourjar.jar
Your Project -> right click -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar
You must add it as "external JAR" files, and set the "Order and Export" in your Eclipse project.
Update February 2012:
Pacerier mentions in the comment having an issue (ClassNotFound) even though he did declare the library.
He had:
However, the solution was simple:
Over 1 hour wasted. Man was I pissed!
Solution: make sure your JAR is compiled with 1.6 and not 1.7.
Argh
Thanks to VonC for pointing me in the right direction. I had the same symptoms but for a different library (I needed to add org.apache.commons.codec.binary.Base64 for an Android project). The solution that worked for me was SLIGHTLY different. Herewith the steps that I followed:
Download library from http://commons.apache.org/codec/download_codec.cgi
Extract commons-codec-1.6.jar from the tarball and copy to a local
folder
In eclipse:
right-click project name
choose "Properties" from context menu
on "Libraries" tab, select "Add External JARs..."
navigate to and select commons-codec-1.6.jar from the location you extracted it to your local drive
The jar file will now appear under "referenced Libraries" in your Package Explorer and you will be able to reference the library in your code.