Reputation: 2557
I am working on AOSP Settings application which builds properly.
I am trying to build "user build" and have enabled proguard using proguard.flags and disabled jack compilation
ANDROID_COMPILE_WITH_JACK := false
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
My question is how can I shrink resources and strip/remove unneeded language string resources that we generally do in build.gradle
using Android.mk file
android {
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
}
}
}
And to keep only US and Indian English
android {
defaultConfig {
resConfigs "en_US", "en_IN"
}
}
My Android.mk file
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(call all-logtags-files-under, src)
LOCAL_MODULE := settings-logtags
include $(BUILD_STATIC_JAVA_LIBRARY)
# Build the Settings APK
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Settings
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_PRODUCT_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.settings
LOCAL_MODULE_TAGS := optional
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_ANDROID_LIBRARIES := \
androidx-constraintlayout_constraintlayout \
androidx.slice_slice-builders \
androidx.slice_slice-core \
androidx.slice_slice-view \
androidx.core_core \
androidx.appcompat_appcompat \
androidx.cardview_cardview \
androidx.preference_preference \
androidx.recyclerview_recyclerview \
com.google.android.material_material \
setupcompat \
setupdesign
LOCAL_JAVA_LIBRARIES := \
telephony-common \
ims-common
LOCAL_STATIC_JAVA_LIBRARIES := \
androidx-constraintlayout_constraintlayout-solver \
androidx.lifecycle_lifecycle-runtime \
androidx.lifecycle_lifecycle-extensions \
guava \
jsr305 \
settings-contextual-card-protos-lite \
settings-log-bridge-protos-lite \
contextualcards \
settings-logtags \
zxing-core-1.7
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
ANDROID_COMPILE_WITH_JACK := false
include frameworks/base/packages/SettingsLib/common.mk
include frameworks/base/packages/SettingsLib/search/common.mk
include $(BUILD_PACKAGE)
# ==== prebuilt library ========================
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
contextualcards:libs/contextualcards.aar
include $(BUILD_MULTI_PREBUILT)
# Use the following include to make our test apk.
ifeq (,$(ONE_SHOT_MAKEFILE))
include $(call all-makefiles-under,$(LOCAL_PATH))
endif
My proguard.flags file
# Some tests use thenThrow from Mockito which require information on
# checked exceptions.
-keepattributes Exceptions
# Keep all Fragments in this package, which are used by reflection.
-keep public class com.android.settings.** extends androidx.fragment.app.Fragment
# Keep all preference controllers needed by slice and DashboardFragment.
-keep class * extends com.android.settings.core.BasePreferenceController {
*;
}
-keep class * extends com.android.settings.core.TogglePreferenceController {
*;
}
# We want to keep methods in Activity that could be used in the XML attribute onClick.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
# Keep setters in Views so that animations can still work.
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
void set*(***);
*** get*();
}
# Keep classes that may be inflated from XML.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int, int);
}
# Keep annotated classes or class members.
-keep @androidx.annotation.Keep class *
-keepclassmembers class * {
@androidx.annotation.Keep *;
}
# Keep specific fields used via reflection.
-keepclassmembers class * {
public static ** SEARCH_INDEX_DATA_PROVIDER;
public static ** SUMMARY_PROVIDER_FACTORY;
}
-keep class androidx.core.app.CoreComponentFactory
# Keep classes that implements CustomSliceable, which are used by reflection.
-keepclasseswithmembers class * implements com.android.settings.slices.CustomSliceable {
public <init>(android.content.Context);
}
# Keep classes that extends SliceBackgroundWorker, which are used by reflection.
-keepclasseswithmembers class * extends com.android.settings.slices.SliceBackgroundWorker {
public <init>(android.content.Context, android.net.Uri);
}
documentation of
Upvotes: 1
Views: 659
Reputation: 1978
You cannot set for one app, but you can set PRODUCT_LOCALES in device or product level, which will take effect for all apps built with aosp.
Take the following as example, it will only include en_US and en_IN.
PRODUCT_LOCALES := en_US en_IN
Upvotes: 0