Android library Declare-Styleable Runtime Error

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

java.lang.NoClassDefFoundError: com.my.pacakge.R$styleable 

If I manually download .aar and turn on that everything works fine in the project. I tried using Android Studio code completion to see if the R library was turned on. When I use the maven dependency, entering com.my.pacakge.R does not return results, but when I use the local .aar, it returns R for the library.

Here is 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> 
+5
source share
1 answer

The problem is that the dependency was published using publishNonDefault true .

+1
source

Source: https://habr.com/ru/post/1206042/


All Articles