Home » Android » Android Build System » How to use LOCAL_OVERRIDES_PACKAGES with example in Android ?

How to use LOCAL_OVERRIDES_PACKAGES with example in Android ?

In Android, LOCAL_OVERRIDES_PACKAGES is a variable used in the Android makefile system (Android.mk files) for specifying which packages to override when building the Android Open Source Project (AOSP). This is typically used when you’re modifying or adding features to the AOSP and want to override specific packages without having to modify their original source code.

Here’s how you can use LOCAL_OVERRIDES_PACKAGES with an example:

  • Identify the Package to Override: First, identify the package you want to override. For example, let’s say you want to override the package com.android.settings.
  • Create or Modify Your Android.mk File: In your project’s Android.mk file, you’ll specify the LOCAL_OVERRIDES_PACKAGES variable along with the package(s) you want to override. If you’re creating a new package, you’ll create a new Android.mk file for it. If you’re modifying an existing one, you’ll modify the existing Android.mk file.
LOCAL_PATH := $(call my-dir)

# List of packages to override
LOCAL_OVERRIDES_PACKAGES := com.android.settings

include $(call all-subdir-makefiles)
  • Define the Overrides: You’ll need to define the overrides in your own package. This typically involves creating a package with the same name as the package you’re overriding. For example, if you’re overriding com.android.settings, you’ll create a package structure like com/android/settings in your project.
  • Implement Your Modifications: Within your package, implement the modifications or additions you want to make to the original package. This could involve adding new functionalities, modifying existing ones, or simply tweaking configurations.
  • Build Your Project: After making the necessary changes, build your project using the standard AOSP build commands (make or mmm).

Here’s a simplified example to demonstrate:

Let’s say you want to override com.android.settings to change the default behavior of a certain activity within the Settings app. You would:

  1. Specify com.android.settings in LOCAL_OVERRIDES_PACKAGES in your Android.mk file.
  2. Create a package structure com/android/settings in your project.
  3. Implement the necessary changes within this package structure, perhaps by modifying existing Java files or adding new ones.
  4. Build your modified AOSP project.

Leave a Comment