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:
java.lang.NoClassDefFoundError: com.my.pacakge.R$styleable
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 com.my.pacakge.R
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) {
setForeground(foreground);
}
a.recycle();
}
// attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ForegroundImageView">
<attr name="android:foreground"/>
</declare-styleable>
</resources>
The issue is that the dependency was getting published with publishNonDefault true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With