views:

62

answers:

2

It am sub-dividing an app I have into "platform" and "app" layers so that I can distribute the platform as a jar for use by partners - while protecting my IP.

I now have two Eclipse projects. Building has no ability to compile any resources into a jar, so I moved all resource references into the app project (the platform project gen/ directory is empty). I compiled the platform and then manually used the jdk to to jar it, imported that jar into the app project, marked the jar for export in the app project, and successfully compiled and installed a test app:

public class NotifyService extends Service {
    ...
    @Override
    public void onStart(Intent intent, int startId) {
        myNotify(intent.getIntExtra(EXTRA_ICON),...));
    }

    private void myNotify(int iconResource, String s1, String s2, String s3) {
        Context c = getApplicationContext();
        if (H.VERBOSE) Log.d(TAG, "myNotify()"); //$NON-NLS-1$
        Notification n = new Notification(iconResource, s1, currentTime);
        Intent nextStep = new Intent(Intent.ACTION_VIEW,Uri));
        PendingIntent pending = PendingIntent.getActivity(c, 0, nextStep, 0);
        n.setLatestEventInfo(c, s2, s3, pending);
        mgr.notify(1, n);
    }... 

The test activity launches as expected and I get the LogCat() message from this service. But no notification is shown and no error is logged - its just silent. ...

Anyway, I want partner apps to make use of my platform which connects to services, content providers, the web, the works. Anyone offer some guidance?

UPDATE!

Hah... typical... when I moved all the resources out of my platform and into my app I did not properly pass these down from the app layer. Thus, the code example I gave had no error. Using an intent rather than linking decouples "arguments passed" from "arguments expected" of course - and the compiler does not complain. With a corrected app, this works.

Though I'd think creating a binary distribution platform is not uncommon, I'm not finding much doc on it so I'll keep adding any significant findings as I open the doors ... hope it's of use to someone.

+1  A: 

You should look at the concept of a "Library project".

Working with Library Projects

[Edit]

@DJC - I see...in that case I would suggest looking at the AndEngine project. The output of that project is a JAR which is then used in the AndEngineExamples project (an example app that consumes it).

AndEngine - Standalone library, distributed as a JAR

AndEngineExamples - Examples app, which consumes the AndEngine JAR

Timothy Lee Russell
Thanks Tim. I will not be distributing my platform as source - I want to retain my IP. Perhaps I misunderstood these words from that reference ... "A library cannot be distributed as a binary file (such as a jar file). This is because the library project is compiled by the main project to use the correct resource IDs." Thats why I migrated all my resource references into the app layer, passing them as arguments (or intent extras) in platform calls. The Google API Library contains two jars, which that same doc says can be referenced..
DJC
@DJC - Per my edit, I realize AndEngine is a pretty specific use case but maybe some of its plumbing will be useful to you.
Timothy Lee Russell
Ty Tim... I'd introduced an error app side, see Update to original post. I'm on my way it seems .. and excited :)
DJC
@DJC -- Cool...
Timothy Lee Russell
A: 

Look into using parcels, its like a Jar only its android specific. I don't have much experience with them but I think they are pretty powerful in terms of re-using activities and views and things.

"It (parcel) wraps up a JAR and other Android-related files that you need to effectively use that JAR." -Advanced Android Develoment

schwiz