我在 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);
}
}
/frameworks/base/package/SettingsLib中的Android.Mk文件
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”,它会成功编译
但是当我对包/应用程序/设置执行“mma”时,它失败了。
预期结果是 AOSP 应该编译成功。
但是构建失败并出现警告。
最佳答案
我找到了删除这些警告的方法。 SettingsLib 中有 proguard.flags 文件,我需要像这样添加
--dontwarn android.support.v7.appcompat.*
--dontwarn android.support.v7.widget.*
就这样,我成功地构建了 AOSP。
谢谢
关于android - 在Android M的AOSP代码中的开发者选项中添加自定义EditTextPreference时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57014307/