Alright so I have a android project and It is working fine. Now i want to take some of the classes in it and put it into a jar and then include that jar in my project. I'm not exactly sure how to do that. The files have R in it and not sure if they will affect anything. Im keeping the xml files in the original project, so basically all i want is the .java files be put into the jar and then referenced.
Is there anyway to do this?
Make a new project for your classes and mark it as library, in eclipse go to
Project properties -> Android and then check Is library
To use your library in a new project, again go to
Project properties -> Android and click Add button and select your library.
You might need to have both projects in the same workspace.
The resources files (i.e. R) defined in you library will be accessible in your new project, so you can use it as if it is defined in your new project.
You can create a separate library project. If you are using the command line, create a directory for the project, cd to it, and use
android create lib-project
The help output will tell you the flags this command requires.
After you move the classes to the library project, cd back to your main project and type
android update project -p . -l <path-to-library-project>
Now when you compile your main project, it will also compile the library project, create a jar file, and import its classes into your main project. For more details about library projects, check out Managing Projects. If you are using Eclipse, check out Managing Projects from Eclipse with ADT.
Related
I added the Google Gson jar file to my Android project by copying and pasting the gson-2.2.4 jar file to the libs folder and then right clicked on the Jar file and then select Build Path > Add to Build Path(I followed this tutorial). Then everything worked fine for me with this jar file, but after pushing to github, when my friends pulling this project, they said that all code relevant to that Gson jar file shows errors. How could I fix this?
Problem 1 : Jar doesnt exist. You probably forgot to add, commit and push your changes to github after adding the jar.
Problem 2 : Jar exists but unrecognised. Ask your friends to remove the existing library from java build path using project properties and add again.
You can create a library project which contains the jar file, and then add this library to your project.
Create library project in eclipse:
File->New->Android application project->Next->Check Mark this porject as a library,
uncheck Create custom launcher icon and Create activity->Finish
Add the library to your project:
Right click your project->Properties->Android->Add->Select the library project you created
->Apply->OK
After finishing these two, you should be able to use Gson, and when pushing your project,
remember to push the library project as well.
I am trying to add external library to android dependancies using eclipse adt. I have a couple of libraries like pull to refresh etc in there. But everytime I add a new library jar file it shows outside of the android dependancies library folder. How do I make it such that it is coupled with the other libraries as a part of android dependancies library. Here's what I did so far:
Project> Properties> java build path > libraries> add jars ( also tried adding external jars), but it always showed my new jar file independantly, i want it to be a part of android dependancies). any clue?
Here's a screen shot, I would like to add it as a part of android dependencies:
I still do not get why that is important to you.
However, when you reference a library project: rightclick project->properties->Android->Add then the jar goes into Android Dependencies.
If you add the jar directly to your project under libs or using build path, then it goes under Android Private Libraries.
Both methods works but referencing a library project can have benefits if you want to alter the code of the library during development.
In my case I had the following in my project.properties file
target=android-18
proguard.config=proguard.cfg
android.library=false
android.library.reference.1=..\\com_facebook_android
android.library.reference.2=../actionbarsherlock
After I changed the last line to
android.library.reference.2=..\\actionbarsherlock
actionbarsherlock.jar appeared in the Android Dependancies and I could run my app without the java.lang.noclassdeffounderror exception
I am a beginer in android.My client gave me a project source code(using native libraries) as a refference.Is there any possibilities to use these source code as library for my android project? If it is possible,how can I access methods of these library file? any one please help me..
Import the project into work space. Right click on the project in eclipse. Goto properties. Choose Android. Check if Is Library chexk box is ticked. If not tick the same. This is a library project now.
To refer the library project in your android project.
Right click on the project in eclipse. Goto properties. Choose Android. Click add. Browse the library project and add the same.
Clean and build.
For more information check the link
http://developer.android.com/tools/projects/projects-eclipse.html
Information regarding library project
http://developer.android.com/tools/projects/index.html
If the Android development tools build a project which uses a library project, it also builds the components of the library and adds them to the .apk file of the compiled application.
Therefore a library project can be considered to be a compile-time artifact. A Android library project can contain Java classes, Android components and resources. Only assets are not supported.
To create a library project, set the Mark this project as library flag in the Android project generation wizard.
To use such a library, select the generated project, right-click on it and select properties. On the Android tab add the library project to it.
The library project must declare all its components, e.g. activities, service, etc. via the AndroidManifest.xml file. The application which uses the library must also declare all the used components via the AndroidManifest.xml file.
Other projects can now use this library project. This can also be set via the properties of the corresponding project.
Please check this
To create a library project, set the Mark this project as library flag in the Android project generation wizard.
http://www.vogella.com/articles/AndroidLibraryProjects/article.html
One thing that has continued to frustrate me as I learn Android development (via Eclipse) is getting Android app projects that reference Android library projects to work reliably. Sometimes the app project won't build because of missing class references that are defined in the library, and sometimes it builds but then crashes at runtime with the class defined in the library is referenced, with an error link
java.lang.NoClassDefFoundError: com.dave.customviewtestlib.LibTestClass
shown in by logcat.
I'm using Android Developer Tools Build: v21.0.1-543035
I've created a workspace with the simplest possible Android app project referencing the simplest possible Android library project. How exactly am I supposed to tie them together in Eclipse? They both build fine by themselves. Then I edit the "Java Build Path" of the Android app project. The confusing thing is, there seems to be a lot of ways to reference the library project. Sometimes one way works, then it stops working and another way that didn't work before starts working. Am I supposed to
In the app project's Java Build Path | Projects, "Add" the library
project, or
In the app project's Java Build Path | Libraries, "Add Jar" and point to to a .jar containing the library's classes and other resources, or
In the app project's Java Build Path | Libraries, "Add Class Folder" and point to the library project's "bin" folder which contains the classes, or
In the app project's Java Build Path | Source, "Add Folder" and point to the library project's source folder, or
Something else?
Also, there is the mysterious Java Build Path | Order and Export tab. What does that mean?
Also I have a related question: are these so-called Android libraries like static libraries (you reference them at build time and the code gets sucked in, and at runtime it is just part of the app binary), or like dynamic libraries (they can get installed separately on the device)? I understand it's all Java and all classes are loaded at runtime by the class loader, but I think there is still an important distinction. Most tutorials and references are so dumbed-down, getting answers is hopeless.
Any help would really help minimize my irritation :)
In the package explorer view:
Right click on the library project -> project properties -> android tab
Check: Is Library.
Right click on the Android Project -> project properties -> android tab
Click the "add" button, and select your library project from the list.
To answer you "static question" the difference between and Android library project and a jar'd library is that the android tools automatically fixes resource (xml) references for your project (the generated R file, etc) and then it packages the classes into a .jar file and adds it to your project's apk. So it is included statically.
As to your build path and order and export tabs. The build path is where you can add: .jar files, other projects in your work space, and additional source files to your project. The order/export tab from this is where you select what libraries/class files are going to be statically included with your project's jar file (or apk in the case of Android projects).
If I decided to use a library project in mine I still have to keep this library project in my workspace. Is there a way to avoid this? Also, does it mean I have to deliver an addition folder of library project with a folder of mine?
Library projects works like a charm, but of course you need to keep them open in the workspace as everytime eclipse builds your project it needs to access all the stuff from the library project.
If you don't want to keep this project open AND you don't plan to change it a lot AND it's not an Android project, it's a JAVA commom project you can build it once and instead of using a library project reference a JAR in your android project
If you want to do this outside of Eclipse, (say you're building from the terminal with ant, ie. in continuous integration, or if you just hate Eclipse.) Just place the library project in an adjacent directory. In your main project, edit project.properties to include:
android.library.reference.1=../LibraryFolderName
If you have more than one library to add, just number them accordingly, ie.
android.library.reference.1=../LibraryFolderName
android.library.reference.2=../AnotherLibraryFolderName