Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio native code compiling is slow

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?

like image 714
Rancs Avatar asked Feb 26 '16 02:02

Rancs


People also ask

Why is Android Studio running so slow?

There may be many plugins in Android Studio that you are not using it. Disabling it will free up some space and reduce complex processes. To do so, Open Preferences >> Plugins and Disable the plugins you are not using.

How do I fix lag on Android Studio?

Android Studio needs at least 8 GB RAM to run better. Change your Hard Disk to SSD. Loading/Compiling/Designing/Writing time will be reduced even in 4GB RAM. Use Power Save mode from File Menu that will reduce lots of background work.

Why is my Gradle build so slow?

Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need.


1 Answers

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.

like image 157
bofjas Avatar answered Oct 02 '22 09:10

bofjas