use Jersey Library in a Android project - android

I try to implement a restful client on android via Jersey library. It works pretty well in a Java project. But when I do it in a android project, always come up an exception: could not find class "com.sun.jersey.api.client.config...." It seems that the library cannot be found even I have added it in the build path.

I believe Jersey currently is not ported to Android. But for example Restlet does explicitly support Android and also implements the same API (JAX-RS).

The jar file needs to physically be located in the directory /libs in your project to be included into the distributed apk and linked to the app at runtime.

Related

Cloud Endpoint API Client Library doesn't contain JAR file

I've just followed exactly what was said in this tutorial and ran the command
/usr/local/google_appengine/endpointscfg.py get_client_lib java -bs gradle helloworld_api.NewsApi
I know my NewsApi service works, I've tested it on the Google APIs explorer.
I get a success message: API client library written to ./getNews-v1.zip
I extracted the zip and found the following files inside the folder (getNews):
No JAR file exists!! What do I use to set up the library in my Android client?
Any ideas? Thanks!
If you want a sources JAR and included dependencies to include in your project use '-bs default' or simply omit that option. Using '-bs gradle' or '-bs maven' assumes you are going to use one of those build tools to build a classes JAR yourself. The 'endpointscfg.py' of course won't compile sources to class files for you as it doesn't have knowledge of any Java environment.
More info in the docs:
https://cloud.google.com/appengine/docs/python/endpoints/endpoints_tool

Using SkyEpub jar library in an android project

I am going to use SkyEpub 3 library in my android application to read ebooks in epub format. To get familiar with the method of using SkyEpub I have downloaded its android demo project from here.
Its demo project is working properly, But when I use the skyepub.jar in my own project, it says some methods and classes from the jar file are undefined. Of course in the mean time I am using an unlicensed version of this library. I want to test it before buying the license if it was ok. I doubt that the errors are because of using the unlicensed version of the library in my project.
Can any one tell me please what is the problem exactly?
Thank you in advance.
Because there are a lot of classes ,which are not in jar, in example project. In the example, they create a lot of classes by extends another classes from jar. I used this jar before.
I found what was the problem. I increased priority of the jar file in eclipse. Now it works.

Cloud Endpoints Generated library not found

I am creating a backend GAE project with Cloud Endpoints. I want also to create an Android application that will consume these endpoints, and I found in the documentation here that I have to copy the java source classes to my Android project to access to the endpoints. I really don't like this approach thinking in the case that I am developing the endpoints for a external client (I don't want to give them my source code, I prefer just give them a jar library to avoid complexity).
I found reading the README file also generated with the endpoints that The generated service-specific library can be found in the top level directory
of the zip file:
google-api-services-noteendpoint-v1-rev20130920182043-1.16.0-rc.jar. But this jar is not generated anymore.
So, copying the source classes is the only way to pass the access to the endpoint to the Android project? Where is this jar that once was supposed to be created?
Thanks so much.
Ok, I found the answer, the jar is not generated but can be generated by maven. The endpoints created has maven structure and you only have to package it to get the final jar. Tested and working.
On eclipse, with Google plugin, clicking on the appengine project you can select:
Google->Generate Cloud Endpoint Client Library, you need to have an associated android project. You can create a android associated project, selecting, when creating a new project: AppEngine Connected Android Project.

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.

Share code between client and server side

I'm developing an Android app with Play framework as backend. There are some classes that are common between the client and server side projects.
If I create a library project or a shared folder in Eclipse, and link the classes to both projects, Play complains that it cannot find the classes, (maybe because it has to be in a folder called 'app'?)
Is it possible to share code between client and server side projects using Play framework?
I don't know the Play framework, but if you create a library in Eclipse, instead of linking to it in the build path you must add it as a library in the android settings of your project. (You find them by selecting your project and pressing alt+enter)
Play uses his own classloader and classpath. So you must put your classes into a jar and this into the lib. Or you create a module for the shared code.
What I ended up doing was link the 'app' folder and specify an inclusion pattern for the shared package.
the problem with jar is that the server needs to be restarted everytime it changes, the source needs to be repackaged and the project needs to be re-eclipsified. As for the library project, i'm not using any android specific code in the shared folders
The way to do it would be:
Create a new project with the code to share. This should provide an API to do what you want to do.
Build the project as a JAR
Link the Jar on PLay (drop it on lib folder) and Android

Categories

Resources