android - 在Android M的AOSP代码中的开发者选项中添加自定义EditTextPreference时出错

标签 android android-6.0-marshmallow android-source

我在 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/

相关文章:

android - WebView 客户端的 onReceivedHttpError 和 onReceivedError b/w 有什么区别

android - 您可以在 Android Marshmallow (API 23) 的运行时权限模型中同步请求权限吗?

java - 将android应用程序库中的图像上传到本地spring服务器

java - 在android中设计一个分数页面

android - 尝试添加包时出现错误 "duplicate entry: com/google/android/gms/internal/zzble.class"

android - Camera2basic 应用程序,在 Android 6.0 LGG3 中具有非常暗的预览

java - 如何在 intellij 中设置 android 源代码?

android - 向 Android 添加新的网络承载

java - 无法从源代码编译未经修改的Android

Android:adbd 无法在生产版本中以 root 身份运行