문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top