Increasing heap size while building the android source code on Ubuntu 15.10

I am trying to build the android source code in ubuntu 15.10, but I got an error. Now I want your help to build the android source code.

including ./tools/external/fat32lib/Android.mk ...
Starting build with ninja
ninja: Entering directory `.'
[  0% 1/21542] Ensure Jack server is installed and started
Jack server already installed in "/home/smile/.jack-server"
Server is already running
[  0% 2/21542] Building with Jack: out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/with-local/classes.dex
FAILED: /bin/bash out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/with-local/classes.dex.rsp
Java heap space
Try increasing heap size with java option '-Xmx<size>'
Warning: This may have produced partial or corrupted output.
ninja: build stopped: subcommand failed.
build/core/ninja.mk:146: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1

#### make failed to build some targets (08:25 (mm:ss)) ####

Then I run "$ java -Xmx2048m" command and I get some lines:

 smile@smile:~/Android$ java -Xmx2048m
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32      use a 32-bit data model if available
    -d64      use a 64-bit data model if available
    -server   to select the "server" VM
    -zero     to select the "zero" VM
    -jamvm    to select the "jamvm" VM
    -avian    to select the "avian" VM
    -dcevm    to select the "dcevm" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

Who can help me how to increase heap size?

Your help will be greatly appretiated to me

Thanks in advance.

smile@smile:~/Android$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.15.10.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

I've just run into same problem.

The problem is that virtual machine which runs jack doesn't have enough memory.

You can try to edit jvm command:

JACK_VM_COMMAND=${JACK_VM_COMMAND:="java -Xmx4096m"}

or to decrease number of parallel jack compilations

SERVER_NB_COMPILE=2

in ~/.jack file.

You can read jack documentation for details.

EDIT: Changing .jack file didn't work for me. After digging a little deeper I found that jack server is started with out/host/linux-x86/bin/jack-admin script and it's parameters can be passed with JACK_SERVER_VM_ARGUMENTS environment variable.

So my solution was to set it and restart jack server before building aosp :

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server

If you are building Android N then Jack config files is changed. apply above suggested configs by following Transition Guide.

find the config you want to change, find where it moved from $HOME/.jack and change it there.

Transitioning from server 1.1 (e.g. Marshmallow) to server 1.3 (e.g. N)

The old Jack server used a $HOME/.jack configuration file. It has now replaced by a $HOME/.jack-settings and a $HOME/.jack-server/config.properties.

If those new files do not exist,

run jack-admin start-server and they will be created.

If you had custom settings in your $HOME/.jack, here's how to adapt those.

Step 1

SERVER_PORT_SERVICE=XXXX Replace with SERVER_PORT_SERVICE=XXXX in $HOME/.jack-settings and jack.server.service.port=XXXX in $HOME/.jack-server/config.properties.

Step 2

SERVER_PORT_ADMIN=YYYY Replace with SERVER_PORT_ADMIN=YYYY in $HOME/.jack-settings and jack.server.admin.port=YYYY in $HOME/.jack-server/config.properties.

Step 3

SERVER_NB_COMPILE=N Replace with jack.server.max-service=N in $HOME/.jack-server/config.properties.

Extra Settings

SERVER_TIMEOUT=ZZ You can replace with jack.server.time-out=ZZ, but it is recommended to keep the default setting of “7200” (2 hours).

Other settings in the $HOME/.jack configuration file do not need to be copied. You should still keep your $HOME/.jack configuration file for the old Jack server because both server versions can run simultaneously.

Taken from Jack server , more on Compiling with Jack