2014-11-02 34 views
5

我有一個庫,在maven central有一些小部件。當我使用gradle這個添加庫作爲依賴關係(從行家中心)的項目,我得到:Android庫聲明樣式運行時錯誤

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

如果我手動下載.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> 
+0

請向我們展示包含依賴關係的構建文件。 – 2014-11-08 16:06:07

+0

我和我的aar有同樣的問題。我無法將我的圖書館放在maven上,因爲它無法使用可定製的屬性。 「publishNonDefault false」不適合我。 – NeoKree 2014-12-08 15:40:13

回答