I’ve been working on some major changes to how JUCE interacts with Android. Mainly driven by the desire to get React Native working with JUCE on Android, but also to allow much easier customisation and the use of multiple JUCE component views within different activities.
Projucer will also leave you custom java files alone! (this has been an annoyance of mine for some time…)
You can get it here https://github.com/adamski/JUCE/tree/android-bridge (rebased against the develop branch)
NOTE: You will need to recompile Projucer and re-export your AndroidStudio project for this to work!
The current version is compatible with React Native 0.31.
I’ve moved all the JNI stuff that interacts with JUCE to the
JuceBridge class, and left
JuceAppActivity to be as minimal as it needs to be. I’ve also left it in the
com.juce package, so you can leave it there if you don’t need to modify it, but if you do you can just copy it over to your package folder e.g.
com.mycompany.myapp and make your changes - e.g. inherit from
AppCompatActivity, implement the
JuceViewHolder has been separated out, and
JuceBridge holds a map of these, which are linked together by the component name. It will use the default MainWindow class, but if you want to create multiple JUCE component views across different activities or Android views you can do e.g:
#if JUCE_ANDROID /* Set up our windows that will be attached to Android views */ myViewContainer = new DocumentWindow("My View", Colours::black, DocumentWindow::allButtons); myViewContainer->setUsingNativeTitleBar(true); // this removes the JUCE title bar on Android myViewContainer->setContentOwned(new MyViewComponent(), true); myViewContainer->setFullScreen(true); myViewContainer->setVisible(true); openGLContext.attachTo (*myViewContainer); // Note this has to be detached before it can be attached to another component // e.g. on switching views or activities // Set up more DocumentWindows... #else // Instantiate MainWindow mainWindow = new MainWindow (getApplicationName()); #endif ... private: ScopedPointer<MainWindow> mainWindow; ScopedPointer<DocumentWindow> myViewContainer; OpenGLContext openGLContext;
Then in your custom activity or view:
JuceBridge juceBridge = JuceBridge.getInstance(); juceBridge.setActivityContext(this); // If this is a new Activity JuceViewHolder view = new JuceViewHolder(this); JuceBridge.ComponentPeerView peerView = juceBridge.getPeerViewForComponent("My View"); view.addView(peerView);
I’ve tested it with the HelloWorld and JuceDemo apps, please test it out and let me know any issues in this thread. I’m sending a PR to the JUCE guys too.