I made a project as a library and now I want to export it in order to use it in others projects. Usually I just take the .jar generated but this time it doesn't work.
I included the .jar like this :
Right click on the project > Build path > Configure build path > Add external jar's
When I use my library, eclipse seems to recognize the classes in the .java files...
I think the problem come from the XML file because when I type the beginning of the class name, eclipse does not offer me the rest like it does with the native classes...
Also in the logcat this error has drawn my attention :
07-23 18:30:52.913: I/dalvikvm(4366): Failed resolving Lcom/example/test/MainActivity; interface 1000 'Lcom/omaflak/pulltorefresh/PullToRefresh$OnStartRefreshListener;'
Someone to help please ?
Right click on your project -> Properties -> Android -> check the "Is Library" box. Now your project can be referenced in other projects when you specify so in the build path.
Another thing you could do is right click-> export, and choose JAR file from the wizard.
Using this method only pulls the classes though. It doesn't seem to pull any layouts/XML
Related
I can’t link Android projects in Eclipse.
I get a VerifyError, and some can’t find class warnings, which I assume means that it’s not getting the library.
I’m using project properties > Java Build Path > Projects.
I can get it to work by referencing the other projects jar. Then setting the source attach so that I can step through the code, but this is a much uglier way of setting the projects up because linking to source and linking to the jar doesn’t allow the use of path variables. So the next person to pick up this project is going to be really confused when the project doesn’t work for them.
Is it possible to directly link projects?
Is it possible to use path variables to reference jars and source
attachments?
It’s so easy to do in Flash Builder…
Also, when I change anything in properties > Android then hit okay, when I open properties > Android the changes have been reverted, what's that about?
If you are asking if an android project can reference a "library" project, the answer is yes; open the properties for the main android project and select Android menu and then at the bottom half of the screen, you can Add your library project to your main project. Note that the "library" project should be set as a library project (same UI allows you to set a project as library)
HTH,
Ali.
assuming you're talking about a library project that you have in your eclipse workspace.
go to properties -> Android
on the bottom half of the screen you should see a "Library" pane.
click add and point it to your library that's in your workspace that you want to add.
click apply afterwards.
i'd remove what you added in that library pane that you're talking about. that's for jar libraries that you've added to your project's libs folder.
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).
I import the file into my other computer and it appears like this. It run properly in my previous computer. I am using this method
File->Import->General->Existing Projects into Workspace, Next
Select root directory: /path/to/project Projects-> Select All
UNCHECK both "Copy projects into workspace" and "Add project to
working sets" Finish
==================================================================================
I get this error:
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Unable to resolve target 'android-7'
This is very common problem. this might be because , your project's .class file is in readonly mode when you move it to the another computer. I suggest you to delete that .class file from the project and clean the project , then run it, it will surely solve your problem.
for "unable to resolve target" error you might double check the following:
Do you have Android2.1 or your specific android library in your project? If not, right click on your project->properties->Android (from left side of dialog)-> Select Android 2.1(or other version) as the Project build Target (from right side of the dialog).
Also, make sure project.properties file contains target target=android-7(or your version).
Also,check if "uses-sdk android:minSdkVersion" contains the correct version in AndroidManifest.xml file
This problem occurs if your JRE is not configured in project built path.
To configure JRE:
In Eclipse:
Right click on your project and select Build Path -> Configure Build Path
Go to Libraries tab click Add Library.
Select JRE System Library and related Android Library click Next
Then select JRE from options as per your requirement. Click Finish
I followed some steps I found here (can't find the URL right now, sorry) to convert my Android project in Eclipse to a layout where 99.9% of my code is in a library project, and then I have 2 other shell projects under the same workspace that are mostly just the AndroidManifest.xml files, and a few resource files. This was done so I can support 2 builds of the same project, with just some minor text/icon changes between the 2. The application name is also different so I can publish both on the Android Market at the same time.
Ever since I did this, about every 10 times I compile, maybe once every day or two, I get "dalvik error 1" and something about "Access already exists" (Access being the name of the first Java unit in my library project).
To "work around" the issue I go in to the Java Build path for my stub-project that I am trying to build, and remove the JAR file from my main library from the libraries tab. Then I can build without the error.
Then a while later (maybe 1 or 2 days) I'll get an error about missing classes when I compile my stub-project (not my library). So I'll go back to the Java Build path and put the reference to the JAR file back in, and all is good again for 1 or 2 days, then I'm back to the same error as before.
Is this just a known issue and something I need to do, or can I resolve by a restructure of my projects/workspaces? Currently I have:
Lib Project - only has 2 libs on build path: Android 2.1 and com.android.ide.eclipse.adt.LIBRARIES
First stub project that uses above lib - has the same 2 libs as above project, plus sometimes I use "Add JAR" to include the JAR from the above project's bin\ folder.
2nd stub project - same libs as first stub project
Should I reference the JAR from my "lib project" using one of the other tabs under build path options? Maybe the "Project" tab instead, or the "Source" tab? I don't currently have it under any of those other areas.
When I get in to the weird state, doing a "Clean project" also doesn't help, I've tried that several times and open/close the IDE between cleaning, to no resolve.
At this point we are in the final testing stages, so my normal daily task is:
Make a minor update (bug fix) in the LIB project
Use the publish wizard to export both projects and update Android Market and other places we keep the APK files
So I'd like those steps to stay simple, without having to open/close multiple workspaces or go through a lot of build steps if possible.
The classical Eclipse/Java way
Add a (workspace) library
Right click the project you want to insert in.
Click Properties.
Select Java Build Path.
Select the Libraries tab.
Now, it depends how you compile your library.
So either do an Add JARs... or an Add Class Folder.
Choose the external variant to use an external source.
That's it.
Add a workspace project
Right click the project you want to insert in.
Click Properties.
Select Java Build Path.
Select the Projects tab.
Click Add... on the right side and you are done.
The additional Android way
Two steps are necessary:
Mark the project you want to use as library project
Reference the marked project
Mark the library project
Right click your project and select Properties.
Select Android on the left and tick the checkbox IsLibrary. Done.
Reference the marked project
Right click your project and select Properties.
Select Android on the left and Add... your marked project. It will be added to the list and is ready to use. Now you are able to access all classes and ressources (e.g. drawables, strings) from the referenced, marked project. Awesome, eh? :)
This is a two-part question about adding a third-party library (JAR) to an Android project in Eclipse.
The first part of the question is, when I try to add a third-party JAR (library) to my Android project I first get the problem of
Error parsing XML: unbound prefix
because I'm trying to use a class from that JAR (and need the prefix somehow defined). What's going on?
Second, (after fixing that--the answer is given below), my application doesn't work on Android and I discover via the debugger (LogCat) that the class I'm attempting to consume doesn't exist.
Caused by:
java.lang.ClassNotFoundException:
com.github.droidfu.widgets.WebImageView...
Why, when I get no compilation or linker error in Eclipse, does it have this problem on the emulator?
These two questions are rhetorical for I'm going to answer them myself below. Other posts in this forum creep up to the problem and elsewhere there is discussion, but I feel that I can be more explicitly helpful for the next guy to come along.
Now for the missing class problem.
I'm an Eclipse Java EE developer and have been in the habit for many years of adding third-party libraries via the "User Library" mechanism in Build Path. Of course, there are at least 3 ways to add a third-party library, the one I use is the most elegant, in my humble opinion.
This will not work, however, for Android, whose Dalvik "JVM" cannot handle an ordinary Java-compiled class, but must have it converted to a special format. This does not happen when you add a library in the way I'm wont to do it.
Instead, follow the (widely available) instructions for importing the third-party library, then adding it using Build Path (which makes it known to Eclipse for compilation purposes). Here is the step-by-step:
Download the library to your host
development system.
Create a new folder, libs, in
your Eclipse/Android project.
Right-click libs and choose
Import -> General -> File System,
then Next, Browse in the filesystem
to find the library's parent
directory (i.e.: where you
downloaded it to).
Click OK, then click the
directory name (not the checkbox) in
the left pane, then check the
relevant JAR in the right pane. This
puts the library into your project
(physically).
Right-click on your project,
choose Build Path -> Configure Build
Path, then click the Libraries tab,
then Add JARs..., navigate to your
new JAR in the libs directory and
add it. (This, incidentally, is the moment at which your new JAR is converted for use on Android.)
NOTE
Step 5 may not be needed, if the lib is already included in your build path. Just ensure that its existence first before adding it.
What you've done here accomplishes two things:
Includes a Dalvik-converted JAR
in your Android project.
Makes Java definitions available
to Eclipse in order to find the
third-party classes when developing (that is, compiling)
your project's source code.
Ensure that your 3rd party jars are in your projects "libs" folder and they will be put in the .apk when you package your application. You may see runtime errors on the device if something in the jar is not supported, but other than that I have had great success with this.
Setting up a Library Project
A library project is a standard Android project, so you can create a new one in the same way as you would a new application project.
When you are creating the library project, you can select any application name, package, and set other fields as needed, as shown in figure 1.
Next, set the project's properties to indicate that it is a library project:
In the Package Explorer, right-click the library project and select Properties.
In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
Select the "is Library" checkbox and click Apply.
Click OK to close the Properties window.
The new project is now marked as a library project. You can begin moving source code and resources into it, as described in the sections below.
If you are using the ADT version 22, you need to check the android dependencies and android private libraries in the order&Export tab in the project build path
First, the problem of the missing prefix.
If you consume something in your layout file that comes from a third party, you may need to consume its prefix as well, something like "droidfu:" which occurs in several places in the XML construct below:
<com.github.droidfu.widgets.WebImageView android:id="#+id/webimage"
android:layout_width="75dip"
android:layout_height="75dip"
android:background="#CCC"
droidfu:autoLoad="true"
droidfu:imageUrl="http://www.android.com/images/opensourceprojec.gif"
droidfu:progressDrawable="..."
/>
This comes out of the JAR, but you'll also need to add the new "xmlns:droidfu"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:droidfu="http://github.com/droidfu/schema"
...>
or you get the unbound prefix error. For me, this was a failure to copy and paste all of the supplied example from the third-party library's pages.
Error parsing XML: unbound prefix
Resource '/playteddy/res' does not exist.
I got the above two errors and finally I solved it.
Right click your project -> properties -> java build path -> googleadmobadsdk (select and put it top), then you run and problem solved. It is solved my runtime error.
Put the source in a folder outside yourt workspace.
Rightclick in the project-explorer, and select "Import..."
Import the project in your workspace as an Android project.
Try to build it, and make sure it is marked as a library project.
Also make sure it is build with Google API support, if not you will get compile errors.
Then, in right click on your main project in the project explorer.
Select properties, then select Android on the left.
In the library section below, click "Add"..
The mapview-balloons library should now be available to add to your project..
Go to build path in eclipse, then click order and export, then check the library/jar, and then click the up button to move it to the top of the list to compile it first.