Compiling Android Studio native code is slow

I recently switched from Eclipse + ADT to Android Studio. My application is a complete C ++ application. I am using Android Studio 2.0 Beta 5 and Gradle Experimental 0.6.0-beta4.

The build process of Android Studio is very slow for native code. I read all the questions about Stackoverflow and the Internet. I applied all the suggested methods (--offline, --daemon, --parallel, -XmxSize, etc.). They are mainly aimed at speeding up the assembly of Java code. The process of compiling native C ++ files (ndk-build) is still very slow. Even if I write one code in C ++, I wait 5-7 minutes every time I click the Run button, where the Eclipse compilation time is about 15-20 seconds for the same work.

Do you have a suggestion to speed up the process of compiling your own code (C / C ++) in Android Studio?

+7
android android-studio android-ndk gradle-experimental ndk-build
source share
1 answer

If you are building on linux, I have a hack 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 execution permissions for the new script:

 chmod 775 ndk-build 

Now, anyone who runs ndk-build (including gradle / android studio) will force the object files into 8 cores at the same time. 8 cores - an example. You must set this for the number of cores available to you. If you set it too high compared to the number of available cores, you usually lose performance. If the processor has hyperthreading, you can double the number of cores.

I'm sure there is an equivalent way to do this on windows with a script package or something, but I don't have an atm machine available for Windows.

+1
source share

All Articles