在Android中的AOSP构建中找不到第三方库资源

时间:2017-12-01 09:47:13

标签: android android-source android.mk

我正在AOSP环境中构建一个Android应用程序( MyApplication ),它使用一个库项目,该项目具有一个自定义的android视图,可以扩展布局。 我已将库项目包含在MyApplication的android.mk文件中。 然后我在MyApplication的布局中添加了自定义android视图。

MyApplication 的Android.mk具有以下条目

LOCAL_STATIC_JAVA_LIBRARIES += mylibrary  

mylibrary的Android.mk有以下条目

include $(CLEAR_VARS)
LOCAL_MODULE := mylibrary
LOCAL_MODULE_TAGS := optional
LOCAL_SDK_VERSION := 21
LOCAL_STATIC_JAVA_LIBRARIES :=android-support-annotations
LOCAL_SRC_FILES := $(call all-java-files-under, library/ui/src/main/java)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/library/ui/res
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_MANIFEST_FILE := library/ui/src/main/AndroidManifest.xml
LOCAL_AAPT_FLAGS += --generate-dependencies --extra-packages com.mylibrary.player.ui --auto-add-overlay
include $(BUILD_STATIC_JAVA_LIBRARY)

现在我已将库中的自定义视图包含在MyApplicaiton的布局中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <com.mylibrary.player.ui.CustomView
        android:id="@+id/idCustomView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

public class CustomView extends LinearLayout {

    public CustomView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setOrientation(LinearLayout.VERTICAL);
        LayoutInflater.from(context).inflate(R.layout.customview, this, true);

        String title;
        String subtitle;
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);

        try {
            title = a.getString(R.styleable.CustomView_customViewTitle);
            subtitle = a.getString(R.styleable.CustomView_customViewSubtitle);
        } finally {
            a.recycle();
        }

        // Throw an exception if required attributes are not set
        if (title == null) {
            throw new RuntimeException("No title provided");
        }
        if (subtitle == null) {
            throw new RuntimeException("No subtitle provided");
        }

        init(title, subtitle);
    }

    // Setup views
    private void init(String title, String subtitle) {
        TextView titleView = (TextView) findViewById(R.id.customview_textview_title);
        TextView subtitleView = (TextView) findViewById(R.id.customview_textview_subtitle);

        titleView.setText(title);
        subtitleView.setText(subtitle);
    }
}

现在,在构建AOSP时,没有构建错误。但是发生了一些运行时异常

   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mylibrary.player.ui.R$layout" 

如何在主应用程序中访问库中的资源?

有人可以指导我让它发挥作用。提前致谢

0 个答案:

没有答案