android : how to start activity defined in library

2020-07-22 09:11发布

问题:

I am developing an android application that uses androidVNC Viewer as a library project, but I am unable to launch an activity from androidVNC (activity not found exception).

Also, how do I bundle a library project and use it as one apk?

UPDATE

I am using following intent to call:

Intent call= new Intent("android.androidVNC.androidVNC.LAUNCH");
startActivity(call);

UPDATE 2 after using following code i think i could start the activity but getting this ( java.lang.NoSuchFieldError: android.androidVNC.R$id.textIP) error...

Intent vnc_call = new Intent(getApplicationContext(), androidVNC.class);
            vnc_call.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(login);

after i checked both R.java,androidVNC original and androidVNC when used as library(under generated java files)...what i got is textip is there in orignal R.java but it is not there in the R.java of (generated java files) in the calling project.

O/P of logcat (first few lines)


04-05 01:34:18.135: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.135: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.135: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)
04-05 01:34:18.135: W/dalvikvm(479): Link of class 'Landroid/androidVNC/ConnectionBean;' failed
04-05 01:34:18.145: W/dalvikvm(479): VFY: unable to find class referenced in signature (Landroid/androidVNC/ConnectionBean;)
04-05 01:34:18.155: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.155: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.155: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)
04-05 01:34:18.155: W/dalvikvm(479): Link of class 'Landroid/androidVNC/ConnectionBean;' failed
04-05 01:34:18.187: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.187: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.187: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)`

04-05 01:34:18.135: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.135: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.135: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)
04-05 01:34:18.135: W/dalvikvm(479): Link of class 'Landroid/androidVNC/ConnectionBean;' failed
04-05 01:34:18.145: W/dalvikvm(479): VFY: unable to find class referenced in signature (Landroid/androidVNC/ConnectionBean;)
04-05 01:34:18.155: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.155: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.155: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)
04-05 01:34:18.155: W/dalvikvm(479): Link of class 'Landroid/androidVNC/ConnectionBean;' failed
04-05 01:34:18.187: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/AbstractConnectionBean; (256)
04-05 01:34:18.187: W/dalvikvm(479): Link of class 'Landroid/androidVNC/AbstractConnectionBean;' failed
04-05 01:34:18.187: W/dalvikvm(479): Unable to resolve superclass of Landroid/androidVNC/ConnectionBean; (8)

any clue?

回答1:

Even though library projects have their own AndroidManifest.xml, its contents are not added to your build. Anything the library contains which is normally declared in the manifest must be copied to your actual application manifest if you plan to make use of them. This includes activities, broadcast receivers, services, permissions, etc.



回答2:

assuming that lib and app have different namespaces:

when merging the lib-manifest-info with the app-manifest as mah described, did you include different namespaces in the activity ?

    <application ... >
        <activity
            android:name=".MyActivity" >...

to

    <application ... >
        <activity
            android:name="my.namespace.MyActivity" >...

using latest eclipse-android tools 1.7 may also help. See how-to-consume-reusable-gui-element-widget-with-resources-in-android for details