1

I try to use the dateslider in my android project to have a combined date-time picker im my gui.

The authors of the widget suggest to include the java- and resource-sources directly into my app.

1st try copy java and resources into main app:

Result: The widget java classes cannot compile because the resourceids R.xxxx cannot be resolved.

Reason: The widget classes are implemented in package "com.googlecode.android.widgets.DateSlider" and my app has a different namespace "my.namespace.myApp" so that the resourceids come from my.namespace.myApp.R.xxx.

To fix this i would have to touch every widget java source to import my.namespace.myApp.

Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?

2nd try put widget java+resources into seperate jar/library:

result: every thing compiled. but after appstart i get a runtimererror: the runtime cannot resolve the widget resource IDs from the jar/lib.

Note: i can call methods from the jar as long as these do not need resources.

So my question: what is the best way to consume a reusable gui element with resources in android?

I am using android 2.2.

Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.

update 16.3.2012

Since the current version 16 /17-pre of of the eclipse adt-tools do not support resources in jars (as of try 2) what is the best/easiest way to consume them until there is support for this?

update 4.4.2012

with the new R17-tools i succeeded to consume libraryproject-with-resources that creates the jar. Android-Lint helped me to find out what to change in the lib to make it usable.

  • eclipse-workspace

    • DateSliberLib
      • src
      • res
      • ...
    • MyAppUsingLib
      • src
      • res
      • ...

    with this layout MyAppUsingLib is running fine


However I am still not able to use the DateSliberlib.jar alone

  • eclipse-workspace
    • MyAppUsingLib
      • src
      • res
      • lib
        • DateSliberLib.jar
      • ...

This setting can be comiled but the app crashes because it cannot find the resources of the lib.

[update 2014-11-17]

6 months ago i switched from eclipse/ant-build to android-studio/gradle build which introduced *.aar files that are jar-files with android resources.

android-studio/gradle build can cope with resources in libs.

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85

1 Answers1

1

Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?

No, sorry.

Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.

However, that is the right answer. Download the full project from their repo, import it into Eclipse, and mark it as a library project (Properties > Android). Then, add it as a library project to your app's project.

Eventually (which now appears like it will be the R18 version of tools or later), the tools should support packaging reusable components in a JAR, with resources, in such a manner that you can add them to a host project and the resources will be blended in automatically. Right now, that's not an option.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • If i understood you correctly my 2nd try was correct to make a jar out of it and i need to update the eclipse adt-tools from 15 to 18 and it should work then. I will give it a try. Thanks – k3b Mar 15 '12 at 15:14
  • @k3b: R18 tools do not exist yet. As I wrote, "***eventually*** (which now appears like it will be the R18 version of tools or later), the tools should support packaging reusable components in a JAR". – CommonsWare Mar 15 '12 at 15:24
  • +1 for info about adttools. I reformulated the question to best practise until adt supports it. thank you very much for info – k3b Mar 16 '12 at 08:35
  • @k3b: I already answered your modified question. Download the full project from their repo, import it into Eclipse, and mark it as a library project (Properties > Android). Then, add it as a library project to your app's project. – CommonsWare Mar 16 '12 at 11:14
  • Today i upgraded to R17 tools. With this i can consume the lib after minimal changes in the layout-file that the android lint tool discovered – k3b Mar 28 '12 at 22:40