Android库声明样式运行时错误

Eli*_*zer 5 android maven android-build android-gradle-plugin aar

我有一个库,在maven中心有一些小部件.当我将该库作为依赖项(从maven中心)添加到使用gradle的项目时,我得到:

java.lang.NoClassDefFoundError: com.my.pacakge.R$styleable
Run Code Online (Sandbox Code Playgroud)

如果我手动下载.aar并将其包含在项目中,一切正常.我尝试使用Android Studio的代码完成来查看是否R包含了库.当我使用maven依赖时,键入不com.my.pacakge.R返回任何结果,但是当我使用本地.aar时,它返回R库的库.

这是库代码:

// 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>
Run Code Online (Sandbox Code Playgroud)

Eli*_*zer 1

问题是依赖项是通过publishNonDefault true.