1

I'm developing an API for Android and it works great but I'm not sure how to package/distribute it. I've gotten the "meat" of the API into a jarfile - that's all the classes and an XML file in res/values/attrs.xml (I'm not sure if there's a way users can reference to that without having to copy my attrs.xml into their /values folder, but that's another question).

While trying my API in a test case, I've added my .jar to the build path and I can import a class successfully if I want to, but I don't want to :P My API allows users to implement a custom View into their own XML files, so nothing is instantiated in code.

The question: How can users reference to a custom View in my API? For example, if my View is called FooView and is in package com.myfoo, the following XML fails to load:

<com.myfoo.FooView
android:layout_width="fill_parent"
android:layout_height="100dp"
/>
Snailer
  • 3,777
  • 3
  • 35
  • 46

2 Answers2

0

Does this have to packaged into a jar , As i see facebook android sdk they give out the source code . I set it up as a new android project and from my android project reference this as library.In that case i am able to access all the apis exposed

Kavitha
  • 461
  • 2
  • 8
  • 22
  • It doesn't "have" to be in a jar.. I just thought jarfiles would be easier for novice developers, as all you need to do is add it to the build path. Assuming this works, that is. – Snailer Aug 17 '11 at 23:12
  • Although since we're on the topic: in your example, how would you reference something from the facebook library in xml? I haven't looked at it.. is it as simple as com.facebook.SomeView? – Snailer Aug 17 '11 at 23:16
  • No you cannot access xmls directly since its a library it will have set of apis exposed and we can access those.If you want to provide some element , you would create a method in your classes which would access and return it when i use it .Does that make sense? – Kavitha Aug 18 '11 at 20:33
  • Check setup part , it will give a idea how to go about it http://android10.org/index.php/articleslibraries/290-facebook-integration-in-your-android-applicatio – Kavitha Aug 18 '11 at 20:35
0

You might want to look into Android Library Projects. These are basically normal android projects, which can be referenced as a library. This means you can define classes, layouts and resources as you would normally, and just use them in your main app (in this case in your clients app) as if they were defined in the same project. This allows you to reference views in XML like you tried above via <packagename.classname ... />.

There is one huge downside though (which is especially important when you create custom views):
styleable-resources simply don't work. This is a bug. According to this question it's going to be fixed in the next devtool release though.

With that in mind I recommend setting up a small test project with a test library project and see if everything that you need works correctly.

Community
  • 1
  • 1