I have a custom preferences control that I have defined a few attributes for in values/attrs.xml. Just to focus the conversation, here is an example of attributes that could be found in values/attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomView">
<attr name="android:text"/>
<attr name="android:textColor"/>
<attr name="extraInformation" format="string" />
</declare-styleable>
</resources>
To use the attributes, you use an xmlns tag where you want to use it, and it looks something like this:
xmlns:custom="http://schemas.android.com/apk/res/com.conundrum.app.lib"
Herein lies the problem: the xmlns definition refers to the LIBRARY's package name, and this resource compiles fine in the LIBRARY project. However, the Android project that includes the Library project has a different package name and Android tries to merge all the resources. When it gets to this xmlns definition, it balks because the package name is different in the including Android project.
Anybody got any ideas for using xmlns references in Library projects that are still valid in including Android projects?
Were declare-styleables just an oversight by the Android team when they considered libraries?
This fixed it for me. I also remember having this issue with Xamarin and the same solution worked for Xamarin.
xmlns:ab="http://schemas.android.com/apk/res-auto"
Me too had the same problem. My app not detected the library-project styleable xml.
I tried this:
My Library Project package : com.lib.mylibrary My Application Project package : com.app.myapp
I tried
xmlns:custom="http://schemas.android.com/apk/res/com.app.myapp
instead of
xmlns:custom="http://schemas.android.com/apk/res/com.lib.mylib
It worked fine ie. try
instead of
I got this idea here
Maybe a bit late, but the issue appears to be fixed in the latest (r14) release of the dev tools.
This is a known issue in Android. A fix is expected in the next release (r13) of the development tools.
Use
http://schemas.android.com/apk/res-auto
I found this solution given casually as a side-note in the AndroidSVG project:
(I fixed a typo - missing /res/ subfolder - in the quoted text above)
I actually played a lot with styleable and libraries and have the following observations:
Imagine that you have a project that has main project and included library:
xmlns:custom="http://schemas.android.com/apk/res/YOUR_LIBRARY_PACKAGE"
Surprisingly what works instead isxmlns:custom="http://schemas.android.com/apk/res/YOUR_MAIN_APP_PACKAGE"
(!) It indeed looks like an overlook from android team, but once you know it, it works flawlessly.