Question

I'm not sure whether I'm running into a bug in the Android tools here, or whether this is by design. The problem is this: I have an Android library project that exports a widget. As part of that widget, styleable attributes are exported in R.styleable:

Library project (package = com.example.mylib):

<declare-styleable name="com.example.MyWidget">
    <attr name="someAttr" format="integer" />
</declare-styleable>

App project (package = com.example.myapp):

<LinearLayout xmnls:mylib="http://schemas.android.com/apk/res/com.example.mylib">
  <com.example.MyWidget android:id="..." mylib:someAttr="1" />
</LinearLayout>

The problem is, the someAttr attribute seems to be only visible to Android/ADT whenever the library and the application use the same package identifier! In this case, they don't, and the ADT fail with the following error:

No resource identifier found for attribute 'someAttr' in package 'com.example.mylib'

Like I said I can fix this by changing the app's package name to "com.example.mylib", but of course this is not what I want! Am I missing something?

Was it helpful?

Solution

This is a known bug #9656. I've written two posts about this issue: here and here. I've explained why this happens and how to patch aapt to fix this issue if you really-really need this fixed right now.

For now, if you do not want to rebuild aapt, you need to move all you custom attributes and layouts that use those custom attributes from library to application.

OTHER TIPS

For anyone that might be still looking for the answer: since ADT 17 you have to use http://schemas.android.com/apk/res-auto as namespace for custom attributes in library projects, works as a charm:

xmnls:mylib="http://schemas.android.com/apk/res-auto"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top