After a while of working with Android Studio and figuring out some things the hard way, I'd thought I collect this knowledge here in this sticker thread, so you don't have to go through the same process on your own.
The basic steps to set everything up are described very well in this tutorial. This thread collects additional info about the current situation, which is subject to change at any time as Google is improving and changing Android Studio. This post is as of 29 April 2016. I'll do my best to keep it up to date.
Please keep in mind that NDK (C++) support in Android Studio is experimental and it is not expected that everything runs smoothly. You might get the occasional "Internal IDE error" or other unexpected behaviour, and might need to close and restart Android Studio if something is not working.
Update 29 April 2016: this sticky post is getting shorter as I keep removing issues that are now fixed by Google.
1. Make sure you are running the newest Android Studio
This includes both the Android Studio app and the Android build tools. Make sure you always use the lateset version. As of April 2016, JUCE supports Android Studio 2.1.
2. Get the native debugger running
[updated on 24 Feb 2016]
First of all, go to the SDK Manager (Tools -> Android -> SDK Manager) and make sure you have LLDB installed:
The next thing to do is to go into your app configuration here and to select app-native as the configuration you want to debug:
Setting breakpoints, looking at the call stack, etc. should all now work.
3. Release vs. Debug configurations
It is not obvious how to switch beetween Release and Debug builds. It is not the "Play" and "Bug" button, respectively (as far as I can tell, both do the same thing...)
Instead, it's here:
To actually build a release build, you also need to sign it. For testing you can use the debug keystore (default setting). But for a proper release build you have to create a keystore with a signing key using the command-line application keytool (documentation here), put it somewhere on your machine, and then when Android Studio asks you to provide a keystore, use the one you created.
Update 2 February 2016: How to run a Release build from within the IDE
If you try to run a release build on a physical device from within Android Studio using the "play" or "bug" buttons, you may get an "Error: Build Type isn't debuggable". In this case, ignore it, click on "Run", and in the next dialogue that pops up click on "Continue Anyway".
4. Building from the command line
Update 29 April 2016: here is how to do that on OS X and Linux:
- make sure your
gradleexecutable is in your PATH or otherwise invokable (it is typically here:
- Go into your Terminal
(this will create the “gradle wrapper” script that will build the app from the command line in the next step)
On Windows, it should also work, although we didn’t test it. The generated wrapper script will be called
5. Known issues
If you ever see this error when opening a project in AS (happens for example after cleaning the build folder and re-exporting from Introjucer/Projucer):
- delete the project from the list on the left by hitting the backspace button while it is selected (blue).
- Click on "Import project (Eclipse ADT, Gradle, etc.)"
- A file dialogue opens. Navigate to the project manually, and in there select the "Android Studio" folder inside the "Builds" folder.
- Import this. It will re-generate the missing .idea file and then the project should open again.
Another thing to keep in mind is the way we currently generate Android Studio projects from the Introjucer/Projucer. Apparently, AS expects all the source code of a project to be inside the project's app folder. However, with JUCE projects it is sometimes unavoidable to include source files that are somewhere else (e.g. in the global JUCE folder). Other IDEs like Xcode, Visual Studio etc. allow you to specify the location of each file that should be compiled, and then to organise them into groups. AS lacks this functionality. The way we currently emulate this common project structure on AS is to build a tree of symlinks inside the app source folder, which then link to the actual source files that may be located somewhere else.
This works just well most of the time, but you should keep in mind that such a symlink structure does not play very well with things like version control systems, compressing the folder, transferring it to another machine etc.
Update 2nd February 2016:
Android Studio seems to be not very good at picking up code changes and realising that it has to recompile (this applies to C++ code, not Java code). You will find yourself having to "Rebuild project" a lot, even if you have changed only one line of code. We are aware of this issue and have forwarded it to the Google Team. In the meantime, please post if anyone knows a solution.
Update 21 March 2016:
Android Studio apparently cannot handle underscores in the app activity class name (see this thread) so you should avoid them.
We highly recommend to use either OSX or Ubuntu for Android Studio development. We strongly recommend not to use AS on Windows for developing JUCE apps as you are likely to run into unsolved issues. If you're brave enough anyway, here's a few tips:
- update 15 Feb 2016: You need to run the Introjucer as Administrator, otherwise Project Saving for Android Studio will not work and you will get a bunch of Introjucer errors about failing to write a file to disk etc.
- JUCE apps won't compile in AS if the JUCE module folder is on another drive than your project. Make sure both your project and the JUCE folder are in C:\, or alternatively set copy-mode for all JUCE modules in the Introjucer/Projucer.
Sometimes, AS seems extremely slow on a Mac and/or is forever stuck at "Build symbols..." so you can't do anything. When this happens, do two things:
1. Increase the available memory. Here's how. Locate the file /Applications/Android Studio.app/Contents/bin/studio.vmoptions. It should look like this:
-Xms256m -Xmx1280m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=240m -XX:+UseCompressedOops
Tweak the numbers to increase the memory available to AS. For example, on my MacBook Pro (Retina, 15-inch, Mid 2014, 2.5 Ghz i7, 16 GB RAM) the following values work nicely:
-Xms512m -Xmx6000m -XX:MaxPermSize=1000m -XX:ReservedCodeCacheSize=500m -XX:+UseCompressedOops
Sometimes, after being stuck for a while, AS will eventually display an "Out of memory" error dialogue. Whenever that happens, you can edit those numbers above directly in that dialogue, so you don't even have to manually edit studio.vmoptions.
2. Disable Instant Run. Go to Preferences -> Build, Execution, Deployment -> Instant Run and untick Instant Run.