17

I am trying to build my own libs and apps in external directory of the AOSP, but the problem is i have to run make each time and the make will compile/build whole the android. In my external apps folder i have Android.mk file, but i cannot build it using ndk-build, it will look for JNI folder and NDK_BUILD_PATH, so the question is:

How can i build it without rebuilding whole AOSP?

joragupra
  • 692
  • 1
  • 12
  • 23
Andrei Golubev
  • 283
  • 1
  • 2
  • 15

3 Answers3

13

A plain make invocation will not rebuild more than necessary, but even with a leaf library or binary even an incremental build can take a few minutes. If you only want to build your particular module you can look at the functions briefly documented at the top of build/envsetup.sh. Specifically, the m and mm shell functions should be useful as they only build one or more modules without caring about their dependencies and without even trying to read all Android.mk files found in the tree. Using them should speed up incremental builds significantly (but all dependencies must have been built at some point, i.e. they're only useful for incremental builds).

build/envsetup.sh also defines a number of other shell functions that are useful for building the Android platform and working with its source code.

Magnus Bäck
  • 11,381
  • 3
  • 47
  • 59
  • Yes, the pain make does not rebuild all, sure, but your suggestion is correct. I will accept it as the correct answer. Thank you. – Andrei Golubev Jan 07 '14 at 02:04
  • 8
    I would like to add to your comment the following: - croot: Changes directory to the top of the tree. - m: Makes from the top of the tree. - mm: Builds all of the modules in the current directory. - mmm: Builds all of the modules in the supplied directories. - cgrep: Greps on all local C/C++ files. - jgrep: Greps on all local Java files. - mgrep: Greps on all makefiles - resgrep: Greps on all local res/*.xml files. - godir: Go to the directory containing a file - printconfig: tells you what configuration you are currently building – Andrei Golubev Jan 07 '14 at 21:15
  • I won't list them all since most of them have nothing to do with the question, but I've modified the response to indicate that the file contains more interesting functions than the ones I mentioned early. – Magnus Bäck Jan 07 '14 at 21:46
10

You can get list of all of the modules in your Android code with the following command:

make modules

To build any single module:

make [modulename]
devrobf
  • 6,973
  • 2
  • 32
  • 46
Shridutt Kothari
  • 7,326
  • 3
  • 41
  • 61
  • If we want to compile just an application or library, do we still need to download (rsync) the whole AOSP ? – ransh Dec 02 '16 at 21:06
8

To briefly address the more general case, mm is a useful command, but the location from which it should be run is not well documented - or more specifically, it is not always clear what is a "module".

Let's say you have made a change to SystemUI, which is a specialized app that is key to the overall functionality of Android. This is part of the frameworks/base repository.

If you just go to the frameworks/base directory, and execute mm it will not find anything to do - your changes will be ignored.

To actually pick up your changes with mm you have to be in the directory where they reside - in this example, you would need to be in frameworks/base/packages/SystemUI. The appropriate location for other codebases will be different - but as a guess, you probably need to be where the Android.mk covering your changes resides.

You can then either use the make snod target from the top of the tree to rebuild the system.img and flash it with fastboot, or use adb remount, adb push the new SystemUI.apk, and then adb shell "start; stop" to restart the Android framework.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117