How to build an Android Project with JUCE

Alessandro Lombardi
4 min readSep 26, 2021

--

JUCE is a c++ framework, and in the course of the last decade it became one of the leading platforms for the development of modern and performant audio applications and audio plugins for digital audio workstations.

JUCE is crossplatform, and it can be used to easily deploy on iOS and Android: this article will focus on how to build a project for Android (the only pre-requisite is to have Android Studio already installed and configured).

1. Download NDK and CMake

First, we need to install the Native Development Kit (NDK) and CMake in Android Studio.

From Android Studio, open Tools → SDK Manager.

Go to Appearance & Behavior → System Settings → Android SDK and select the SDK Tools tab:

Android Studio SDK Manager

Make sure to select NDK and CMake, then click OK and start the download.

The JUCE official tutorial also suggests to download LLDB, which is no more available from the SDK Tools list, but don’t panic, because with more recent versions of Android Studio, LLDB is already installed during the standard installation of the Android SDK.

2. Download JUCE and set the Global Paths

You can download the free version of JUCE here. The download is pretty small and comes with the Projucer, the JUCE custom compiler, which is what we are going to use to create a new Android project.

First, JUCE needs to know the exact location of the Android SDK. Open the Projucer, then go to File → Global Paths and enter the SDK location:

Projucer Global Path Window & Android SDK Location
  • for Windows OS, SDK usually lives inside C:\Users\{your name}\AppData\Local\Android\SDK
  • for Mac OS/Linux: /Library/Android/SDK

3. Create a newproject

To create a new project, run the Projucer app, then go to File → New Project:

Projucer — Create a new project

Select Audio, enter a custom project name, choose Android as Exporter and then click Create Project. This will open a new Window:

Projucer — The New Project Window

From the left panel, select Android and (optionally) choose the Minimum and Target SDK.

Notice that 29 is the current (September 2021) maximum SDK supported by the latest JUCE release, so do not try to enter 30 or above as target SDKs, or the build will fail.

The green Android Icon will run the new project inside Android Studio, but if you try to run the app, the build will probably fail: in order to successfully run your app, follow the steps in section 3.

3. Run the app

Once you created the New Project, quit the Projucer, run Android Studio, then go to File → Open and select the location of your New Project. The project tree should look something like this:

Android Project Tree

The native c++ code lives inside the three files:

  • Main.cpp
  • MainComponent.h
  • MainComponent.cpp

MainComponent is a class that extends the Juce Core class AudioAppComponent. This class is responsible for handling at the same time UI/user Inputs and the audio processing (on a separate thread).

In particular audio processing will be manged by the getNextAudioBlock method. Read and follow the official tutorials for more detail.

If you now run the app, the build will be successful:

Android app built with JUCE

Notice that what you see is not standard XML layout. Instead, this is native c++ layout, which is handled inside the MainComponend.cpp.

If you want to use standard XML layout, you need first to disable the native UI from the Main.cpp: just find the constructor of the MainWindow class and change the setVisible method from true to false:

setVisible (false);

Then:

  • create a new main Java/Kotlin activity
  • in the Android Manifest, put the intent filter inside the new activity tag:
<activity
android:theme="@style/Theme.AppCompat"
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
  • inside the new Activity tag, remember to set the Android theme:
android:theme="@style/Theme.AppCompat"
  • re-run the app.
JUCE Android App with standard XML layout

The problem with this approach is that now Java/Kotlin and native code are completely decoupled, and you need to use JNI to connect these two worlds. The information on how to achieve this result, even in the JUCE forum, is really rare and sparse, but I will post a new article whenever I will find a solution or an elegant workaround.

--

--