JUCE and Java Android UI


#1

In my mission to try and create a smooth and intuitive UI for my app, I've come up against some limitations of JUCE on Android as it currently stands. So I've been looking into breaking out the UI part into Java, and keeping JUCE for audio processing and data manipulation. This way, I can still use some of the Components I've built for desktop versions. I plan to have initially one view that will be the JUCE Activity with an OpenGLView, and another that will be for editing data with Android UI elements and layout. I've read its also possible to have Android buttons etc overlayed on top of a native view. 

Anyone here done this? Tips, encouragement, wisdom, pitfalls etc welcome. 


#2

I haven't done any overlay stuff, but additional activities I've managed to use. One caveat here is that you should postpone the starting of other activities (with android.os.Handler), otherwise I found that GLSurfaceView.onPause sometimes locks up the app.


#3

Optimising the android rendering is very high on our to-do-list!


#4

Thanks Jules, I know you guys are looking at this. I just reached a point of frustration with a laggy touch UI on Android.

I've been studying the latest Android API - a lot of cool stuff in there for UI development, animations, transitions, gestures, z-height etc. I'm also interested in learning how to do C++ backend and native Java/Obj-C front end similar to the Djinni framework from Dropbox. However, managing multiple UI implementations is something I'd like to avoid if possible! Thats part of the attraction of JUCE in the first place. 

Anyhow, I've decided to redesign my UI to rely less on component dragging, and probably shift focus to iOS for a bit, in the hope that JUCE will soon be better optimised for Android.


#5

I experimented a bit with a native Java UI in combination with a JUCE. It worked.

You would need to adapt the generated JUCE Activity for your own needs and implement a lot of JNI bridge classes when you call from Java to C++ and from C++ to Java.

I also managed my Makefiles for the native C++ part by hand because my app has a few more library dependencies which needed to get integrated.

Finally I was able to utilize Android Studio to implement the Java UI and utilize JUCE and the rest of my code in the native part.

Writing the glue code between Java and native C++ using JNI really hurts even though Jules already has a lot of good helper classes for that in JUCE which can be used to ease the pain a bit.


#6

Hi Jules! We’ve been developing specifically for android currently and we find the rendering indeed slow especially with scrolling. I might just not been able to find additional information in the forum, but is android optimisation still one of your top priorities? And if so, will we have some significant improvement in the next couple of releases? I know the complexities of android can be a pain. Thanks!


#7

First you need to make sure you are rendering using OpenGL. If you need smooth scrolling on Android (or iOS) you will currently need to use a native view. There are two approaches to this - use native views within your JUCE app (not something I’ve done on Android, but seen it done on iOS), or wrap your JUCE component(s) in a native Android/iOS app, so you can have native lists and navigation.

If you want to try the second approach for Android I have a fork I’m working on which should help with that: Modifications to JUCE Android implementation


#8

Hi adam. Thanks for the suggestion :slight_smile: I’ve seen you updates for specifically for the HelloWorld and Demo examples and was trying to export either two projects to android studio but found errors while building…

Specifically with this line:

#if ! (defined (JUCE_ANDROID_BRIDGE_CLASSNAME) && defined (JUCE_ANDROID_BRIDGE_CLASSPATH))
 #error "The JUCE_ANDROID_BRIDGE_CLASSNAME and JUCE_ANDROID_BRIDGE_CLASSPATH macros must be set!"
#endif

Checking my gradle file I found these:

cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSNAME=com_yourcompany_jucedemo_JuceDemo")
cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/yourcompany/jucedemo/JuceDemo\"")

so I just updated JUCE_ANDROID_ACTIVITY_CLASSNAME to JUCE_ANDROID_BRIDGE_CLASSNAME and JUCE_ANDROID_BRIDGE_CLASSPATH and that did work but now it’s complaining that JuceBridge java class is not found…

I may be doing a very stupid mistake here or missed something along the way… Apologies as I’m not yet that good Juce/C++ in general… Thanks so much!


#9

Yes, you need to recompile Projucer with my branch of JUCE and export it again, that will generate all the necessary parts.


#10

@adamski hey I’ve been trying to get your juce-native-navigation project to build, but when saving the project from Projucer, I’m getting “failed to create symlink from …/juce-native-navigation-master/Builds/AndroidStudio/app/src/main/jni/Source/Data.h to …/juce-native-navigation-master/Source/Data.h”.

I’m using the rebuilt Projucer from your branch of JUCE, and I’ve sudo’d it. Googling around taught me that it would usually have to be with the file already being there (which it is), but removing it didn’t seem to solve it. Any idea what might be causing the issue?


#11

Sorry no. That project is quite old now and does not represent the best way to do this on iOS, but the Android part is fine. You don’t need my modified Projucer fork to run it.

It might have included some of the files already, in which case try to delete the jni folder in the Builds folder (it shouldn’t really be there!) and then run it again?

I might update the project at some point but don’t have much spare time atm!


#12

Hey thanks! That worked, but now I’m getting a bunch of “no resource found that matches given name…” errors:

Error:(21, 21) No resource found that matches the given name: attr ‘windowActionBar’.
Error:(22, 21) No resource found that matches the given name: attr ‘windowNoTitle’.
Error:(13) Error retrieving parent for item: No resource found that matches the given name ‘Theme.AppCompat.Light.DarkActionBar’.
Error:(17, 21) No resource found that matches the given name: attr ‘colorAccent’.
Error:(15, 21) No resource found that matches the given name: attr ‘colorPrimary’.
Error:(16, 21) No resource found that matches the given name: attr ‘colorPrimaryDark’.
Error:(19) Error retrieving parent for item: No resource found that matches the given name ‘ThemeOverlay.AppCompat.Dark.ActionBar’.
Error:(24) Error retrieving parent for item: No resource found that matches the given name ‘ThemeOverlay.AppCompat.Light’.
Error:(21, 21) No resource found that matches the given name: attr ‘windowActionBar’.
Error:(22, 21) No resource found that matches the given name: attr ‘windowNoTitle’.
Error:(13) Error retrieving parent for item: No resource found that matches the given name ‘Theme.AppCompat.Light.DarkActionBar’.
Error:(17, 21) No resource found that matches the given name: attr ‘colorAccent’.
Error:(15, 21) No resource found that matches the given name: attr ‘colorPrimary’.
Error:(16, 21) No resource found that matches the given name: attr ‘colorPrimaryDark’.
Error:(19) Error retrieving parent for item: No resource found that matches the given name ‘ThemeOverlay.AppCompat.Dark.ActionBar’.
Error:(24) Error retrieving parent for item: No resource found that matches the given name ‘ThemeOverlay.AppCompat.Light’.

I tried fiddling with the build-tools version with no success…any idea what causes this? I am using it for Android btw, wanted to understand how to pass data from C++ to Java, are you actually the single one that attempted this, since I couldn’t find anything on using native Android UI components with JUCE, apart from your forum posts and JUCE conference video… ?


#13

Look like Android i.e. not JUCE related errors to me…


#14

@adamski and anyone else,
Is Android development in JUCE better with JUCE 5 out? (released April 2017)

I want to make a score notation app for desktop and tablets ( iOS and Android) using 2D graphics. I started writing it in Java SE in 2008 but stopped the project in 2010. The graphics worked rather well, very fast refresh for playback.

I want to sync the app with DAW’s like Logic Pro via a plugin and perhaps use OSC for mobile devices if need be. From what I’ve read, it’s do-able in Java.

But two code bases are required for Java, Java SE for desktop and Codename One, for iOS, Android and Windows Phone, as a mobile cross-platform framework example among five ( link below).

I studied and tutored C++ in College a long time ago. Since I’m getting back into programming after 7 years, JUCE seems to be easier, more modern, with more audio-related libraries.

So it all comes down to this: is JUCE still finicky for mobile graphics and mobile development?

If I want to use a Java lib/package, I can call it from C++.


Review: http://geeknizer.com/develop-android-ios-wp8-apps-using-java/
See also:
Avian
XMLVM
J2ObjC
Intel’s Multi-OS Engine


#15

We (ROLI) are in the midst of releasing NOISE on Android (obviously, NOISE is built with JUCE) and a lot of big and small Android improvements have made it into JUCE 5. This will definitely continue as we continue to work on NOISE.

There are some nice utility function to interoperate between Android and JAVA in JUCE. Simply define JUCE_CORE_INCLUDE_JNI_HELPERS=1 before including any JUCE headers and then you can write things like this:

#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
 STATICMETHOD (getMinBufferSize, "getMinBufferSize", "(III)I") \
 METHOD (constructor,       "<init>",           "(IIIII)V") \
 METHOD (getState,          "getState",         "()I") \
 METHOD (startRecording,    "startRecording",   "()V") \
 METHOD (stop,              "stop",             "()V") \
 METHOD (read,              "read",             "([SII)I") \
 METHOD (release,           "release",          "()V") \

DECLARE_JNI_CLASS (AudioRecord, "android/media/AudioRecord");
#undef JNI_CLASS_MEMBERS
...
...
minBufferSizeIn  = (int) env->CallStaticIntMethod (AudioRecord, AudioRecord.getMinBufferSize, sampleRate, CHANNEL_IN_STEREO,  ENCODING_PCM_16BIT);

(sample copied from juce_android_Audio.cpp)


#16

So is this UI completely made in JUCE?

I am really thinking about making an audio app with JUCE for android UI wise and using a pre-existing audio engine I have used in other apps.

My thought is to start creating some Android specific UI components for apps in a year or two that would use my own audio engine once Android devices get faster.


#17

Yes completely in JUCE.