NoClassDefFoundException when using javax.tools package - android

I'm developing an android app in eclipse and am having some trouble importing some libraries into my build. Specifically, I'm using some classes in the javax.tools package, which is included in the jre7 system library. For some reason it isn't available during runtime, even though I've told the library to export to the build path.
I've tried to isolate the package I need and adding them as an external .jar as was suggested on some android/stackoverflow forums but I was having trouble with that. Considering the package is part of the standard java library, is there an easier way to include it in the final build?
Thanks, I appreciate the feedback!

The standard Java library is a little bit different from android Java library. In eclipse preferences -> Java build path -> Order and Export -> tick the check box of your external jar, compile and build again.

Related

how to use android project library in eclipse?

I am new in android. I see a lot of android libraries out there like github.com but when I download them none of them are a *.jar file like this one:
NumberProgressBar
It seems that all these libraries are for android studio NOT eclipse (Am I correct? This is important).
My question is: How do I use these libraries in eclipse?
I tried to import the downloaded library as an android project and then mark it as "is library" and then add to my project, but that did not work.
That library is designed to be built with Gradle for Android (with or without Android Studio), producing an AAR.
Eclipse does not have native AAR support. I have published a recipe and a Ruby script to convert an AAR into a library project that Eclipse can use, though I have not tested it much.
Or, you can download the source code and attempt to reorganize it into an Eclipse-style library project.
I just downloaded it and add it as library project and everything looks fine. How do you do it, it's extremely simple. Let us know in which step you have a problem so we can figure out what is wrong.
You have to build the library first.
For your example, read the Readme file, section 'Build'.

Expose an "Android Library Project"'s included jars to Projects which reference them

One of the newer functions of Android is the ability to create a Library Project.
This is great for unit testing and sharing common functionality across many apps you may be developing, but I seem to have stumbled upon a bug in their implementation.
When you have the following situation:
-LibraryProject contains LibraryProject/libs/folder/lib.jar in it's build path.
-ReferencingProject references LibraryProject.
From ReferencingProject you don't have access to anything inside lib.jar (Such as constant's used to communicate with methods in the Library Project).
A solution to this is to include "lib.jar" as an external library in the referencing project but this approach begins to negate the benefits you gain from having a self contained Library Project by creating multiple manually added references to resources which could move/change during the development of the library project (not to mention cause some pretty confusing errors).
Is there any way to expose an included libs classes to the referencing project without having to manually reference them as external jars?
As #Selvin says,
In the Library Project you can specify which libraries you want to mark as "exported" in the window brought up by using: Project properties => Java Build Path => Order and Export. From this example you would check libs/folder/lib.jar.
Clean and build the Library Project and the "exported" libraries are now included in the produced jar.
EDIT
This is a symptom of upgrading to ADT 17 - (Android Team: Perhaps put a few warnings on your release notes when an update breaks existing architectures?)
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
If you don't want to add the library to the "Order and Export" then placing local jar's in /libs/ base folder will automatically add it to "Android Dependencies" which are exported in the jar created from your shared library.
EDIT2
Recent ADT upgrade would have you also manually select "Android Dependencies" as "Exported" in your Java Build Path. Again, warning would be nice.

Sharing Java library with Android Apps

I'm just getting started in Android development, and use Netbeans with NBAndroid and SDK 17.
I'd like to use the same Java source code in my Java and Android app.
http://developer.android.com/guide/developing/projects/projects-eclipse.html says how to do it in Eclipse (although it is sketchy on the .JAR connection thing), but I can't seem to make it work in NB.
Based on that link, My understanding is that the correct setup for the Android app is an Android Application project which references an Android Library project which in turn references a .JAR library produced by a Java Library project. I could then also have a Java Application project referring to the same Java Library project.
So, I've set up this project structure... I have an AndroidApp project which is a basic HelloAndroid Activity in a com.ex package. This project includes an AndroidLib library project in the Libraries folder. I also have a LibClass.java file which defines a simple LibClass class which has one function getText() that just returns a String to be displayed. The MainActivity in the AndroidApp calls this to get the String to output.
When I put LibClass.java directly into the AndroidLib project, everything is fine.
But what I want to do is to share the source code with Java.
So I want to move the LibClass.java into the JavaLib library, whose .JAR file is included in the AndroidLib project. However, when I tried that, I get an error in the MainActivity class, complaining it can't find LibClass. Looking at the Projects window, I can see LibClass.class inside the com.ex package in the JavaLib.jar in the Libraries folder of the AndroidLib project. And AndroidLib is visible in the Libraries folder of the AndroidApp project, but it doesn't show any packages or other contents there.
So I feel like I'm just one step away from making this work. Do I need to do something with one or other of the AndroidManifest files perhaps? Or do something with the build.xml files? Or am I on the wrong track altogether?
I'd be really grateful if someone could post a how-to for this.
I'm trying something similar; I've got Java EE projects, built using Eclipse, and I'm trying to utilize some of that code from my Android projects. This should give me a shared codebase rather than a bunch of confusing SVN externals which I've had to endure before.
Rather than creating JAR files I've found that working with the source and building for the platform works best (well, it has been working but I've got a problem with it at the moment). So, what I'm doing is:
c:\MySvnFolderStructure\MyJavaProjectFolder\src\ (and then all the source under that)
c:\MySvnFolderStructure\MyJavaProjectFolder\android\ (and all the Eclipse Android project gubbins)
c:\MySvnFolderStructure\MyJavaProjectFolder\jee\ (and all the Eclipse JEE project gubbins)
The Android and Java EE projects do not have their own src folders, they both link to the src folder in their parent folder. What this means is that each of the Java implementations is building its own byte code version from the source, and using its own external libraries (like the Apache HTTP ones, for example).
Naturally they can't share stuff like awt (as mentioned in another post), but there's plenty of stuff that does cross-over especially if it's core Java classes that are being used.
Also, it's proving a bit tricky writing JUnit tests as there needs to be some duplication of the test code at the moment because the Android ones need extra instrumentation, but I'm working on it.
Also, see this post about relative paths in Eclipse, which means the folders can be checked-out to different places on different machines (like we all do with our version control check-outs) and still be shared.
if I understand your situation correct, you are trying to use a custom java library for both your android and java applications.
For this scenario, you can build the java library first. Instead of adding the java library jar as android library, you can drop the jar directly inside the libs folder of android project and add it to android project's build path.
If you are using ANT scripts for building the java library jar , you can consider adding the source files also as part of jar. This will help you get code assistance when you develop the android part. But this part is purely optional.
The problem is that the Java platform in Android is different from the JDK platform.
In particular, the .JAR library CANNOT refer to anything that is not icluded in the Android platform. An example of things you can't refer to is java.awt.* (except you can have java.awt.fonts).
There is also a difference between JDK String and Android String -- Android does not implement the isEmpty() method.

Does an Android library project also export its external libraries?

I'm developing a software layer that I would like to reuse several time for building my Android applications. Basically I want that, once installed, the software layer any other apps can use it (like a system library).
I was wondering what is the best solution for doing this, when I found that recently Android supports library projects (http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject).
So I decided to create my software layer as a library project, making the code it contains re-usable by the other applications I want to realize.
My software layer depends on a set of external jar, which are correctly located in the lib folder of the library project.
The problem is that when I create a new project referencing the library project I'm not able to see the classes defined into the external jars of the library project: i.e. it seems that they are not part of the classpath.
So when referring to a library project is possible to re-use only the source code defined there? If my library project have some other libraries I have to import these libraries also in the other ones (I want to avoid this!)?
I'm also interested to know if there are other ways for doing this, but searching around I haven't found other ways for realizing Android libraries/shared code.
Thanks.
Android library projects definitely incorporate any JARs you have in the library project's libs/ directory. However, if you are using Eclipse, you probably have to somehow manually add those to your build path of the host project (the one reusing the library).
Ok I finally figured out that for solving this is sufficient to add the jars to the host project build-path (no need to re-import them, you can just choose the path from the library project). However it is weird that they are not automatically exported in the host project classpath.

Android adding external libraries to project

I have a project that I would like to add external libraries to (and have them packaged with the application) but I am not sure it is happening. I read on this link:
https://developer.android.com/guide/appendix/faq/commontasks.html
how to, but they do not show up in any of the /data/data/project directories. Does anyone know how I can confirm that the libraries were in fact added to the project for use at runtime? Thanks.
If you include jars as External Jars under your project's Java Build Path, then the classes will be converted to Dalvik format and be made available in your project's classes.dex file, packaged into the .apk.
To confirm they are available, attempt to use something from the jar (Eclipse should suggest the relevant import when you first supply a class name) build and run the app and see if it works? If it works in development (e.g. from 'run' in Eclipse) then it will also work when the app is built in release and distributed as an APK.
You can also place jar under one of your source folders (perhaps creating special "libs" one) and adding it to build path.
Be warned - external libraries (which are compiled against some version or other of the libraries in a Java JDK) may sometimes have problems when running under android. This is because the Dalvik runtime has its own Java framework libraries, which provide most (but not all) of the Java APIs in the standard JDK Java framework libraries.
You should really recompile any external library against the android libraries so that you can see any missing APIs at compile time - and fix the issues there and then. Otherwise you run the risk of runtime errors under Dalvik when you call the external library from your Android app. See http://geekswithblogs.net/cyberycon/archive/2011/05/17/using-external-libraries-with-android.aspx
for more details.

Categories

Resources