Android Studio native code compiling is slow

3k Views Asked by At

I recently switched from Eclipse+ADT to Android Studio. My app is a full native C++ application. I use Android Studio 2.0 Beta 5 and Gradle Experimental 0.6.0-beta4.

The build process of Android Studio is very slow for the native code. I read all questions on Stackoverflow and Internet. I applied all suggested methods (--offline, --daemon, --parallel, -XmxSize, etc..). They mostly addresses to speed up the build of Java code. The compiling process of native C++ files (ndk-build) is still very slow. Even if I write one line C++ code, I wait 5-7 minutes each time I click Run button, where the compiling time of Eclipse was around 15-20 seconds for the same job.

Do you have any suggestion to speed up the compiling process of the native code (C/C++) on Android Studio?

2

There are 2 best solutions below

0
On BEST ANSWER

I will give an answer to my old question to close it.

In the end of the story, we integrated cmake into the project. It works as fast as old Eclipse build performance.

2
On

If you're building on linux I've got a hack for you to speed up the NDK build:

cd <ndk-bundle-path>
mv ndk-build ndk-build2

Now create a shell script called "ndk-build" containing the following:

#!/bin/sh
$(dirname $0)/ndk-build2 -j 8 $@

Now set the execute permissions for the new script:

chmod 775 ndk-build

Now, anyone who launch ndk-build (including gradle/android studio) will be force to bang out object files on 8 cores simultaneously. 8 cores is just an example. You must set this to what ever number of cores you have available. If you set it too high compared to the number of available cores you'll usually lose performance. If the CPU have hyper threading you can double the the number of cores.

I am sure there is a equivalent way of doing it on windows with a batch script or something but I don't have a windows machine available atm.