How i can create usable android project's library

by Ali Adnan » Wed, 12 Aug 2009 23:10:25 GMT


Sponsored Links
 How i can create android project's library that can be used in any
different project.

Problem:
I create a jar file that contains all activities and add this jar file
into my eclipse project build path. But if i need to use any activity
then i must need to register this jar activity into my project
AndroidManifest.xml. This looks very odd. I need a solution in which i
have a jar or any other deployable file that contains multiple
activities and any user can use them in his project without
registering these jar activities into NEW android application
AndroidManifest.xml file.

Ali Adnan.

--~--~---------~--~----~------------~-------~--~----~



How i can create usable android project's library

by Mark Murphy » Wed, 12 Aug 2009 23:13:10 GMT


 


That is not possible.

As I wrote 5 hours ago:

Bear in mind also that your library cannot package any resources, making
activities that much more difficult to package in a library.

You can see a library that I package with an activity here:

https://github.com/commonsguy/cwac-custmenu/tree

Anyone using this library will need to both list my MenuCustomizer
activity in their manifest, but also pass in a couple of resource IDs by
integer extras on the launching Intent, to get around the fact that
MenuCustomizer cannot have its own resources.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Development Wiki:  http://wiki.andmob.org 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How i can create usable android project's library

by kostmo » Thu, 10 Sep 2009 07:22:54 GMT


 > Bear in mind also that your library cannot package any resources, making

I'm not sure that is true.

I have created a .jar from a project that happens to include some
layout files.  I import this .jar from a second project, and add a few
lines to the second project's Manifest file:

    <activity
android:name="com.googlecode.chartdroid.ChartPanelActivity"
android:theme="@android:style/Theme.Translucent">
        <action
android:name="com.googlecode.chartdroid.intent.action.PLOT" />
        <category android:name="android.intent.category.DEFAULT" />
    </activity>

When I launch the .jar'd activity from the second activity with an
implicit intent, it appears to work fine.  The layout resources that
the .jar'd activity uses exist only within the .jar file.
--~--~---------~--~----~------------~-------~--~----~



How i can create usable android project's library

by Mark Murphy » Thu, 10 Sep 2009 07:33:53 GMT


 


*blink, blink*

How do you have the resources packaged in the JAR?

Thanks!

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 1.0 In Print!

--~--~---------~--~----~------------~-------~--~----~



How i can create usable android project's library

by kostmo » Thu, 10 Sep 2009 08:42:02 GMT


 Oops, I'll have to retract that; my test was invalid.  The manifest
lines I added were incorrect (forgot the <intent-filter> tags),
causing my new version not to be installed...

I do indeed find problems in my log now, such as:
09-09 19:28:11.484: WARN/ResourceType(580): No package identifier when
getting value for resource number 0x7f060000

-and-

09-09 19:29:18.184: ERROR/AndroidRuntime(3002): Caused by:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'

followed by F/C.

Sorry for the mix-up!

I was also misled by the fact that I could reference the ID's of the
resources inside the JAR, suggested by Eclipse's autocomplete
behavior.

I think the best way to accomplish what I was intending will be to
install an entirely separate .apk with the libraries.

Karl





--~--~---------~--~----~------------~-------~--~----~