Create Android apps in Eclipse sharing common library - java

is it possible to create java libraries the apps can use shared?
It is totally clear to me how to create a library project and how to use it while shared between several another projects, compile each project into different apps.
But in this case the library gets compiled into each app separated.
What I want is to create a library, compile it, install it into the device (or emulator) and several apps calling into this library.
And when it is needed to change something the apps use shard in this library, I just re-work the library, re-compile it, replace it on device (or emulator), and the apps use the new library, all apps use the new functions.
Is it possible?
I googled it, but I couldn't find the solution.
I am using Win + Eclipse, I can't use native code (since I know only Java).
Thanks
UPDATE: Thank you for your suggestions, I know about using Services and Activities started explicitly in order to share functionality.
I asked about libraries because I am investigating the possibilites. If there is no way to use common library, what is the purpose of uses-library... in the app manifest?
Thank you

It's more likely that you need a service as a library. Have you considered this possibility? You can create it as a separate application, define an interface for your service and use it in other apps. So as the interface does not change this will not influence on other apps that depends on this service.

The Android model installs each application as a separate user (UID) on the device and the users have no access to other application's/user's files. Therefore, you can't share libraries as such.
As Yury suggested, you might need a service or an activity that can be invoked from multiple applications.

Related

Sharing file across library project

I am writing a library project which can be installed across multiple apps.
In order for the library to function it needs to download files. My goal is to download the files once and share them across other instances of my library in other apps. (I want to save the network traffic), how do I achieve this. Public external storage is not an option for me.
If you want to share functionality between different android applications, you should implement the Inter-Process Communication (IPC) between them.
Since android applications are actually sandboxed linux processes, they do not have access to each other's private data and files.
In the domain of Android development, there are two ways to implement IPC :
Messengers and AIDL ( Android Interface Definiton Language), which both make use of the bound services in application.
I recommend you to start studying the aformentioned documents to get a big picture on the subject.

Separate UI from Logic in Android

I recently read a blog post by the Gmail team on the approach they used to develop the different platform versions for Inbox for Gmail. The short story is that they write everything in Java (so basically for Android) but separate all the UI code from the shared logic code. Then for iOS they reimplement the UI in a platform specific iOS manner but use a program they developed (and open sourced) called J2ObjC to convert the shared logic from Java to Objective C.
I understand how to get this working on the iOS but how should I arrange the classes on the Android? I understand that I need to create separate classes for the different parts of the shared logic but how do I this practically so that a) all the shared logic is in its own directory so I can easily reference it on it's own and b) I can still reference it from my activities.
Based on my searches I think I need to use the MVP pattern but I'm not 100% sure.
I put the model logic in a separate project with no Android dependencies. Another project depends on the shared project and contains the user interface and builds the Android project.

Java Library in Android Project

I want to make a java library (so I can compile it into a jar) that makes calls to a server. I then want to share this amongst android application projects so that I can access those simple calls.
Is using HTTPRequest the best way to do this?
http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html
Something about making web calls in the java way and sharing them in android apps seems odd to me. should this be an Android Library instead? (I believe those should only be used when resources are involved)
Sorry for the potentially simple question.
You can develop a common Java library that you can use with both android , and regular java projects.
Take a look at OkHttp , it shows you how to achieve this. It is related to HTTP client, may be it already provides everything you need. You can extend it where needed.
For a simpler example (~20 java classes), take look at Okio , the underlying io library used by OkHttp.

Create Android library jar to work with non-Android project

I am working on a library that ideally will have a strictly-Java component and added functionality for Android-specific projects, with the intent to be most useful for Android apps, but also work with other Java apps.
But my question is: how should this be designed? I do not plan on needing resources, so I want to compile it into a JAR, but would I need to make two JARs, one of the Java stuff and another for the Android stuff? Or would a Java-only application be able to use a single JAR so long as it does not use the Android components?
If you make a library that uses pure java and does not use any android apis. It will work on both standard java and android java. However if the library uses any android apis it can't be used in a standard java project.
As far as I know, the JAR would be good for both types of aplications. It seems to mee that both JARs (just Java and android) are totally identical and thus equally compatible. If you don't use any of the android components, including Resources there should not be a problem at all.
You should still check whether you depend on libraries which are available on android and any normal Java distribution or -if not- either tell the user to preinstall the depending libraries or ship them whitin your JAR package and build path. Be carefull not to use libraries which are not available on android because the user has no or really few options to install them on himself.
What I don't understand is why you think your library is more usefull to android developers. I can not think of any example where this could happen. If the problem is really specific for android, you should consider developing the library android-only. If the problem is more general the lib will be usefull to all developers that might come to this problem, not just android.

Using parts of android lib in non-android project

I am currently attempting to port an android app to desktop. I realize that the majority of the android based code cannot be reused, but what about "smaller parts" which dont depend on the android architecture?
I am mostly talking about support or math related classes like SparseArray, Matrix and so on.
Those may work. But you will have a rough time figuring out what works and what doesn't. Even once you do that you will need to create a whitelist somewhere like in your IDE that doesn't auto-complete classes you don't want or can't use and you will also want to fail your build. Maybe you should create a jar containing only the classes you want to use that you determine are usable.

Categories