tags:

views:

1651

answers:

1

Hi,

My Android application can be divided into a client UI layer and a API layer. i would like to deploy them as separate "applications" so that the API layer can be reused.

In Eclipse, i write them as 2 separate Android projects. In the client UI project, i declare the API project in its build path (Project -> Properies -> Java Build Path -> Projects).

When deploying the client UI project through Eclipse (on my actual G1 phone), it automatically deploys the API project (packaged into APK) as well.

However, when launching the client UI application, i hit this error:

Uncaught handler: thread main exiting due to uncaught exception
java.lang.VerifyError: myapp.android.testuiclient.Main
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1472)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
    at android.app.ActivityThread.access$2100(ActivityThread.java:116)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4203)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    at dalvik.system.NativeStart.main(Native Method)

Looking around, it seems like i should declare uses-library under application in the manifest file for the UI client.

Question is, what should i put under android:name for uses-library? Dev guide says "the name of the library" but what is the name of the library? (i mean, in my API "application", i haven't declared any library name anywhere.)

+4  A: 

I do not believe <uses-library> is relevant here.

Your options are:

  1. Implement your "library" as a JAR, to be included in other projects at compile time. So long as your library is not attempting to define resources, you are in fine shape. See the CWAC projects out on my github page for samples of how to set this up.

  2. Implement your "library" as a separate APK containing a remote service, defined using AIDL. Do not attempt to blend their build paths as you are presently doing in Eclipse, but rather follow the AIDL rules and have each project use a common AIDL definition. You will also need to arrange for your users to install both APKs.

  3. Implement your "library" as a separate APK containing a ContentProvider. Do not attempt to blend their build paths as you are presently doing in Eclipse, but rather follow the ContentProvider rules and have the client access the provider via a ContentResolver and a defined Uri. You will also need to arrange for your users to install both APKs.
CommonsWare
Thanks! From the look of it, option 1 is most applicable. i'll have a look at your projects for reference.
Edwin Lee
Hi CommonsWare, i've looked at your CWAC-Cache project. 1. i can see that you use Ant build.xml to build and assemble the JAR. For another project to use that JAR, how do you set it up in Eclipse so that (a) at coding/compile time, the dependency is resolved, and (b), at deploy time, they get built into a single APK and deployed? 2. i suppose CWAC-Cache is not meant to be run standalone (am i correct?). In that case, why do you still need to configure an Activity in the AndroidManifest.xml with a MAIN action and a LAUNCHER category? Is that required?
Edwin Lee
Simple: I don't use Eclipse. :-) CWAC-Cache has a sample demo activity (if you compile the APK), but its primary role is the `ant jar` target to create the JAR of just the actual caching code that other projects can use. The `ant jar` task skips the demo code (isolated in a `.demo` sub-package).
CommonsWare
i see... i would suppose then that you use the command line aapt and apk tools for package and deploy purposes? Thanks for the suggestions! i'll give it a go!
Edwin Lee
Well, I use the `ant` targets, which in turn use `aapt` and `apk` and stuff.
CommonsWare
Hi, sorry, i'm still not fully getting it. i looked at the build.xml file for CWAC-Cache, there is a clean task that cleans the bin and gen directories, and a jar task that packages compiled code from bin/classes into a jar file. However, there isn't a "compile" task to compile the source code to bin/classes? When i used a similar build.xml, after doing clean, i did a jar, and there is nothing to jar.
Edwin Lee
2. Also, could you kindly point me to example build files which take compile classes + dependency jar files and APKs them into an Android package? i looked at vidtry, andwell but couldn't find such an example. Many thanks!!
Edwin Lee
'However, there isn't a "compile" task to compile the source code to bin/classes?" -- there is a dependency set such that `ant jar` will execute `ant debug` first (which I should probably fix someday...). Look at the definition of the `jar` task in `build.xml`. "could you kindly point me to example build files which take compile classes + dependency jar files and APKs them into an Android package?" `cwac-cache` does that -- look in the `libs/` directory at the included JARs.
CommonsWare
1. Do you mean that there is supposed to be a "debug" task in the build.xml which is not there yet? 2. Sorry, still don't understand this... yes, i see some dependency jar files in CWAC-Cache's libs directory. but i still can't see how these jar files are built together into a single .apk file for deployment to a device. Thanks!!
Edwin Lee
Sorry! i think i understand now!! "release" and "debug" are implicit ant tasks that does the compilation and APK, and no need to define them in the build.xml. In addition, when doing APK, it will also package in the jar files in the libs directory without having to explicitly declare them! Thanks so much!!
Edwin Lee