Android Library Declare-Styleable Runtime Error

By : Eliezer

I have a library with some widgets in maven central. When I add that library as a dependency (from maven central) to a project using gradle, I get:


If I manually download the .aar and include that in the project, everything works fine. I tried using Android Studio's code completion to see if the library's R was included. When I use the maven dependency, typing returns no results, but when I use a local .aar it returns the R for the library.

Here's the library code:

// widget constructor
public ForegroundImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundImageView);
    Drawable foreground = a.getDrawable(R.styleable.ForegroundImageView_android_foreground);
    if (foreground != null) {

// attrs.xml
<?xml version="1.0" encoding="utf-8"?>
    <declare-styleable name="ForegroundImageView">
        <attr name="android:foreground"/>
By : Eliezer


The issue is that the dependency was getting published with publishNonDefault true.

By : Eliezer

This video can help you solving your question :)
By: admin