Search code examples
androidandroid-6.0-marshmallowandroid-source

Error during adding custom EditTextPreference in Developer Option in AOSP Code of Android M


I am adding new EditTextPreference in Developer Options menu in Android M. When I created CustomEditTextPreference AOSP build fails with warning:

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

I've created CustomerEditTextPreference in frameworks/base/packages/SettingsLib

Also modified the Android.mk & Common.mk in SettingsLib.

When I'm trying to use the CustomEditTextPreference from Settings under packages/app/Settings/ it fails with warnings

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 file in /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 file

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

If I do "mma" under this directory it compiles successfully

But when I do "mma" of packages/apps/Settings it fails.

The expected result is AOSP should compile successfully.

But the build is failing with warnings.


Solution

  • I figure out the way to remove those warnings. There's proguard.flags file in SettingsLib where I need to add like this

    --dontwarn android.support.v7.appcompat.*
    --dontwarn android.support.v7.widget.*
    

    That's it and I was able to build AOSP successfully.

    Thanks