在 Android M 的 AOSP 代码中的开发人员选项中添加自定义 EditTextPreference 时出错
Error during adding custom EditTextPreference in Developer Option in AOSP Code of Android M
我正在 Android M 的开发人员选项菜单中添加新的 EditTextPreference。当我创建时 CustomEditTextPreference
AOSP 构建失败并显示警告:
Warning: android.support.v7.widget.SwitchCompat: can't find referenced
class android.support.v7.appcompat.R$attr Warning:
android.support.v7.widget.SwitchCompat: can't find referenced class
android.support.v7.appcompat.R$styleable Warning:
android.support.v7.widget.SwitchCompat: can't find referenced class
android.support.v7.appcompat.R Warning:
android.support.v7.widget.Toolbar: can't find referenced class
android.support.v7.appcompat.R$attr Warning:
android.support.v7.widget.Toolbar: can't find referenced class
android.support.v7.appcompat.R$styleable Warning:
android.support.v7.widget.Toolbar: can't find referenced class
android.support.v7.appcompat.R$styleable
我在 frameworks/base/packages/SettingsLib
中创建了 CustomerEditTextPreference
同时修改了SettingsLib中的Android.mk & Common.mk。
当我尝试使用 packages/app/Settings/ 下设置中的 CustomEditTextPreference 时,它失败并显示警告
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v14.preference.EditTextPreferenceDialogFragment;
import android.support.v7.preference.EditTextPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
public class CustomEditTextPreference extends EditTextPreference {
public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditTextPreference(Context context) {
super(context);
}
}
Android.Mk 文件在 /frameworks/base/package/SettingsLib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_USE_AAPT2 := true
LOCAL_MODULE := SettingsLib
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-preference \
android-support-v7-appcompat \
android-support-v14-preference
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.recyclerview:android.support.v7.preference:android.support.v14.preference
#LOCAL_JAR_EXCLUDE_FILES := none
LOCAL_SRC_FILES := $(call all-java-files-under, src)
include $(BUILD_STATIC_JAVA_LIBRARY)
Common.mk 文件
ifeq ($(LOCAL_USE_AAPT2),true)
LOCAL_STATIC_JAVA_LIBRARIES += \
android-support-annotations \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-preference \
android-support-v7-appcompat \
android-support-v14-preference \
SettingsLib
else
LOCAL_RESOURCE_DIR += $(call my-dir)/res
LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.settingslib
LOCAL_STATIC_JAVA_LIBRARIES += \
android-support-annotations \
android-support-v4 \
SettingsLib
endif
如果我在这个目录下"mma"编译成功
但是当我执行 packages/apps/Settings 中的 "mma" 时,它失败了。
预期结果是 AOSP 应该编译成功。
但是构建失败并出现警告。
我找到了删除这些警告的方法。 SettingsLib 中有 proguard.flags 文件,我需要像这样添加
--dontwarn android.support.v7.appcompat.*
--dontwarn android.support.v7.widget.*
就是这样,我能够成功构建 AOSP。
谢谢
我正在 Android M 的开发人员选项菜单中添加新的 EditTextPreference。当我创建时 CustomEditTextPreference
AOSP 构建失败并显示警告:
Warning: android.support.v7.widget.SwitchCompat: can't find referenced class android.support.v7.appcompat.R$attr Warning: android.support.v7.widget.SwitchCompat: can't find referenced class android.support.v7.appcompat.R$styleable Warning: android.support.v7.widget.SwitchCompat: can't find referenced class android.support.v7.appcompat.R Warning: android.support.v7.widget.Toolbar: can't find referenced class android.support.v7.appcompat.R$attr Warning: android.support.v7.widget.Toolbar: can't find referenced class android.support.v7.appcompat.R$styleable Warning: android.support.v7.widget.Toolbar: can't find referenced class android.support.v7.appcompat.R$styleable
我在 frameworks/base/packages/SettingsLib
中创建了 CustomerEditTextPreference同时修改了SettingsLib中的Android.mk & Common.mk。
当我尝试使用 packages/app/Settings/ 下设置中的 CustomEditTextPreference 时,它失败并显示警告
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v14.preference.EditTextPreferenceDialogFragment;
import android.support.v7.preference.EditTextPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
public class CustomEditTextPreference extends EditTextPreference {
public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditTextPreference(Context context) {
super(context);
}
}
Android.Mk 文件在 /frameworks/base/package/SettingsLib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_USE_AAPT2 := true
LOCAL_MODULE := SettingsLib
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-preference \
android-support-v7-appcompat \
android-support-v14-preference
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.recyclerview:android.support.v7.preference:android.support.v14.preference
#LOCAL_JAR_EXCLUDE_FILES := none
LOCAL_SRC_FILES := $(call all-java-files-under, src)
include $(BUILD_STATIC_JAVA_LIBRARY)
Common.mk 文件
ifeq ($(LOCAL_USE_AAPT2),true)
LOCAL_STATIC_JAVA_LIBRARIES += \
android-support-annotations \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-preference \
android-support-v7-appcompat \
android-support-v14-preference \
SettingsLib
else
LOCAL_RESOURCE_DIR += $(call my-dir)/res
LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.settingslib
LOCAL_STATIC_JAVA_LIBRARIES += \
android-support-annotations \
android-support-v4 \
SettingsLib
endif
如果我在这个目录下"mma"编译成功
但是当我执行 packages/apps/Settings 中的 "mma" 时,它失败了。
预期结果是 AOSP 应该编译成功。
但是构建失败并出现警告。
我找到了删除这些警告的方法。 SettingsLib 中有 proguard.flags 文件,我需要像这样添加
--dontwarn android.support.v7.appcompat.*
--dontwarn android.support.v7.widget.*
就是这样,我能够成功构建 AOSP。
谢谢