Android Studio tips, tricks & known issues

Just tried to  update from Android Studio 1.5 to 2.0. Clicking "Release Notes" as described above leads to a website where I can download a zip file. Should I do something with that zip file? Extract it over the existing Android Studio installation or so?

Just restarting Android Studio after having clicked "Release Notes" does not make the button "Update and restart" appear on my machine. I must be missing something...

Let me google that for you:

Thanks. Got a few steps farther now. Behaved a little funny - and did not replace the installation of Android studio 1.5 so I now have both versions. Still fighting, not able to debug yet, but proceeding. I will post updates when I have more news.

Done lots of fighting and lots of updates in the while, but it doesn’t work yet. I keep getting build errors, namely this apparently known issue:

Having to wait for the next update, i guess.

Well, this looks like an Android Studio and/or gradle bug, so can’t really do much about it :frowning: except reiterating for the 100th time that you should not use Android Studio on Windows because so many things are not working properly. For Android development, switch to Ubuntu or a Mac.

Since Android Studio 2.1 Beta 3, there is another bug which basically breaks the clang toolchain on OS X. I submitted the bug here: but could not find any workaround. It is therefore recommended that everyone compiling JUCE apps with Android Studio uses the gcc toolchain instead (it’s a build setting in the Projucer). I changed the Projucer so that gcc is now the default option.

They now fixed that bug in gradle wrapper version gradle-experimental:0.7.0-rc1. So the clang toochain works again!

And if that isn’t enough good news: the clang toolchain now also works on Windows!

I have changed the Projucer to use clang again as the default setting for the Android Studio exporter, as recommended by Google.

I cannot get the latest release of jucer to build for gradle. I go through the steps to generate the wrapper (which is successful) then I run the debug build command, ./gradlew assembleDebug, and get…

In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/app/src/main/jni/juce_gui_extra.cpp:9:
In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_gui_extra/juce_gui_extra.cpp:40:
In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_gui_extra/juce_gui_extra.h:53:
In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_gui_basics/juce_gui_basics.h:55:
In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_graphics/juce_graphics.h:55:
In file included from /Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_core/juce_core.h:169:
/Users/mikef/Desktop/JUCE-master_4_2/examples/Demo/Builds/AndroidStudio/…/…/…/…/modules/juce_core/system/juce_StandardHeader.h:53:10: fatal error: ‘memory’ file not found

Then after a few of those scrolling past clang crashes. Any ideas? I just updated to the latest everything but not being able to find memory seems odd

Looks like either of those:

  • the path to the C++ standard headers is wrong
  • you don’t have the NDK installed
  • you are using the wrong toolchain
  • it’s an Android Studio bug

What OS are you on? Looks like you are using the clang toolchain? What are you trying to build? The JUCE Demo? Your own project? Do you use the default build settings that the Projucer uses, or custom ones? Did you make sure to re-build the Projucer from the newest tip?

Mac OS 10.11.3.

This is the latest Juce checkout from Github setting up the Demo project using Projucer with default settings and nothing changed but my SDK location.

I did a full reinstall of the SDK/NDK/Android Studio and made progress. In Android Studio the demo project builds and fully installs and runs. However when I go to build with command line I get…

/Volumes/Android/buildbot/out_dirs/aosp-ndk-r11-release/build/tmp/build-72234/build-libc++/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/atomic:922: error: undefined reference to ‘__atomic_fetch_add_4’
/Volumes/Android/buildbot/out_dirs/aosp-ndk-r11-release/build/tmp/build-72234/build-libc++/ndk/sources/cxx-stl/llvm-libc++/…/llvm-libc++abi/libcxxabi/src/cxa_handlers.cpp:112: error: undefined reference to ‘__atomic_exchange_4’
/Volumes/Android/buildbot/out_dirs/aosp-ndk-r11-release/build/tmp/build-72234/build-libc++/ndk/sources/cxx-stl/llvm-libc++/…/llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp:106: error: undefined reference to ‘__atomic_exchange_4’
/Volumes/Android/buildbot/out_dirs/aosp-ndk-r11-release/build/tmp/build-72234/build-libc++/ndk/sources/cxx-stl/llvm-libc++/…/llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp:117: error: undefined reference to '__atomic_exchange_4’
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Wonder why it works in Studio but not at command prompt

Oh yeah. Now I know what’s going on. std::atomic doesn’t work/compile on pre-ARM7 (armeabi). There’s nothing we can do about that. So probably when you build from Android Studio, you have the ARM 7 architecture selected (armeabi-v7a in Build Variants). But when you build from the command line then gradle will always build all your architectures.

The fix is to remove armeabi from the architectures you are targeting.

I installed Juce today (awesome tool!) and I had issues on Android. Android Studio 2.1.3 on OS X complains Gradle sync failed: Gradle version 2.10 is required. Current version is 2.14.1.

I did not find a solution here but elsewhere, so maybe this is helpful for others:

In Projucer, create your Export target Android Studio, then in gradle version, override the default with 2.14.1, and in the line below, gradle-experimental wrapper version, use 0.7.3.

Everything else seems to be allright. I do get a warning about split APKs, but I can solve that with the Build Variant trick mentioned above.

1 Like

If you’re up for using the experimental Gradle plugin for Android Studio, I’ve updated my Github repo (on the develop branch to use Android Studio 1.5, and the latest experimental Gradle plugin (0.6.0-alpha3).
With this new plugin, there are a few changes required to the build.gradle files.
Please note, though, if you try to use SWIG AND the native auto-generation, the auto-generated code will be placed in the incorrect location in your SeePlusPlus_wrap.cxx file (it manually needs to be moved inside the “extern C” block.
You can read more about android ndk in android studio with swig if you like.

Is AS under Windows still discouraged?
If no, whichSDK and Tools versions would be recommended?

The Projucer project defaults will use the latest platform tools version for you. The SDK depends on the oldest phone you still want to support. If you are using midi you should use SDK version 23. But we also regularly test version 10.

Thanks @fabian! My main question was, if AndroidStudio with Juce under Windows is still discouraged (as the sticky post still says this).
I got it running meanwhile under Windows 10 with the defaults (=min. SDK 23) but with an Emulator with API 25.
With API 23 emulators (tried 2 different ones), even the hello world example under Windows crashes reproduceably (with juce A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xeaeef000 in tid).

So I would say, Windows might work now, but we should use an emulator >= API25.
Does this sound reasonable?

Yes, that sounds very reasonable. In fact, I’ve always had issues with the emulator under windows - especially when trying to use opengl: any app using opengl (like JUCE) would just crash (probably the crash you are seeing). I then started using the built-in VM of Windows Pro (which supports Android) and that seemed to work a bit better. But haven’t tried newer API versions in the android emulator. Thanks for the tip.

Hi Fabian, any more details on this? thx

Just fire up the Android emulator from Visual Studio. You will need a Windows Pro license though.

Sounds interesting, thanks for the tip :slight_smile: