10

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?

Rancs
  • 165
  • 1
  • 10
  • Try to separate the ndkBuild step as described in http://ph0b.com/android-studio-gradle-and-ndk-integration/ – Alex Cohn Feb 26 '16 at 06:38
  • @AlexCohn That puts the job out of the Android Studio. It may be an option for the Java apps which do not deal with native files but using some native libraries. My app is a pure native app. I am looking for a solution inside gradle-experimental build system. – Rancs Feb 26 '16 at 07:38
  • 2
    One trick could be to limit the ABIs that Android Studio builds – Alex Cohn Feb 26 '16 at 11:03
  • 1
    I work with only 1 ABI during development. – Rancs Feb 26 '16 at 11:15
  • 1
    I have more than 50 cpp files in the jni folder. I feel gradle-experimental compiles everything from scratch whenever I click the Run button. – Rancs Feb 26 '16 at 11:42
  • No, this does not happen for me – Alex Cohn Feb 26 '16 at 17:08
  • Hey @AlexCohn thanks for the efforts. I don't think you use the gradle-experimental plugin 0.6.0+. It is different and more developed than the previous versions. It compiles the native code without leaving the scope to makefiles. But the compilation is slow. I am looking for a solution for the compilation speed in the pure gradle-experimental scope. – Rancs Mar 01 '16 at 14:22
  • I've been using 0.6.0 for a while; today I made another check with the latest `com.android.tools.build:gradle-experimental:0.6.0-beta5`, and no, I don't see rebuild of C++ files when I hit "Run" or "Make". – Alex Cohn Mar 03 '16 at 14:27
  • @Rancs I'm using gradle-experimental plugin 0.7.0-alpha4 and I'm having the same issues. Were you able to solve this? – kristoffz May 31 '16 at 18:00
  • 1
    @kristoffz Unfortunately not yet. Because of this problem, I couldn't switch the production from Eclipse to Android Studio yet. I am more stressed with the time passing. – Rancs Jun 01 '16 at 07:06
  • @Rancs Now 3 years passed and i run into this too. Even if i don't touch the C++ files and only change java the starting is so slow i drives me mad. Have you found a solution? – Lothar Jul 09 '19 at 16:51
  • @Lothar Our story is ended up with integrating cmake, which is as fast as old Eclipse build performance – Rancs Jul 10 '19 at 18:46
  • What a drag. Reminds me of this: https://ib.paths.ws/EjHqOp8O – Uval Apr 19 '21 at 20:26

2 Answers2

1

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.

bofjas
  • 1,186
  • 7
  • 19
  • Why **8** cores? Is that an invariant? – IgorGanapolsky Jul 26 '16 at 21:13
  • That's just because I have 4 cores with hyper threading. You should set it to what ever you have available. If you set it higher than the number of physical cores (double if hyper threading) you usually lose performance. – bofjas Jul 27 '16 at 09:37
0

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.

Rancs
  • 165
  • 1
  • 10