开发者

Android: How to Use "uses-library"?

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开发者_Go百科 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.)


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜