3

I have an application that I now want to split part of off into a library project so I can re-use it in several other places. Among the stuff in there being re-used is a custom view, which uses code from this answer (http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android) with some adaptations I made to it. Anyway, the styleable resources don't work properly. The attr.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <declare-styleable name="VerticalTextView">
        <attr name="text" format="string" />
        <attr name="textColor" format="color" />
        <attr name="textSize" format="dimension" />
        <attr name="rotateLeft" format="boolean" />
    </declare-styleable>
</resources>

and it's referenced in a layout file in the library project. I get the following error in Eclipse when trying to compile the main project:

[2010-12-20 23:29:38 - MyApp] C:\Library\res\layout\main.xml:124: error: No resource identifier found for attribute 'text' in package 'com.mydomain.mylibrary'

I'm puzzled. I've tried everything I can think of to get this to work, and I just haven't found the magic combination. How do I make styleable resources work inside of a library project?

jjb
  • 3,560
  • 1
  • 21
  • 30
  • i guess its too late but have u looked at this http://stackoverflow.com/questions/6471742/android-library-project-uses-declare-styleable-how-to-compile – jsp Jul 19 '11 at 23:18
  • It's a bit late for this project, but in the future, I'll give that a try. Thanks. – jjb Jul 20 '11 at 03:42

2 Answers2

6

The issue has been fixed in ADT 17: to use custom styleables defined in a library project, you have to use the http://schemas.android.com/apk/res-auto namespace, so, considering the example from the question:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto" ... >
    ...
    <com.foo.bar.VerticalTextView
        custom:textColor="#cafebabe"
        custom:rotateLeft="true"
        ... >
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
1

I have failed all attempts to get this working in a library package earlier this month and eventually gave up. To remedy the situation I just added the source files as 'linked' (still external from the project and shared) and this has been working for me.

smith324
  • 13,020
  • 9
  • 37
  • 58
  • Well, apparently this just doesn't work. I found a thread talking about this here: http://groups.google.com/group/android-developers/browse_thread/thread/fc9ac9f168a2ec4f/33ac0c1a69e8d86c?lnk=gst&q=library+project+attr&pli=1 – jjb Dec 27 '10 at 06:20