androidbuildcompilationmakefileandroid-source

Efficiently build Android system service component


I'm trying to extend Android's PackageManager functionalities modifying this file:

frameworks/base/services/core/java/com/android/server/pm/SELinuxMMAC.java

When I perform a make clean && make after editing the file and I start the emulator, the changes are there, but this takes too long even with the cache enabled. I tried using mmm framework/base but it does not seem to rebuild the services.core module.

Does anyone know a reliable method to modify a system service and then rebuild efficiently?


Solution

  • mmm and submodules

    1. Create the new classes.dex for the services.core module:

      mmm frameworks/base/services/core
      
    2. Creates the services.jar file including the services.core module that we just rebuilt:

      mmm frameworks/base/services
      
    3. Creates the new system.img for the emulator:

      make snod
      

      If the emulator (or the device) is already running, you can use the new services.jar with:

      adb remount && adb sync && adb shell stop && adb shell start
      

    In fact mm and mmm do not check for modified submodules, so rebuilding the services module (step 2) without previously rebuilding the services.core (step 1) module is not enough.


    DEXPREOPT

    If you see the message:

    Warning: with dexpreopt enabled, you may need a full rebuild.

    You have to turn off the dex preoptimization performing a make clean and then use the following flags in make and mm: WITH_DEXPREOPT=false and DISABLE_DEXPREOPT=true.