Loading repository data…
Loading repository data…
audiooffler / repository
A simple iOS &Android example for how to integrate Flutter (Dart) as user interface and JUCE (C++) as backend.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A simple mobile app example (iOS, Android) that uses a Flutter (Dart) UI and JUCE (C++) as backend.
Created a JUCE GUI project JucyFluttering with Android and iOS exporters (well it does not really show a GUI, but has a message loop running, to provide timers, event handling etc.)
Created a flutter plugin project (subfolder fluttering) for platforms android and iOs, using Java for android, and ObjectiveC for iOS
flutter create --template=plugin --platforms=android,ios -a java -i objc flutteringfluttering/libJUCE is already does a good job at setting up all the platform-dependend boilerplate code to instantiate and run iOs and Android apps. Some adjustments had to be done to do the Flutter instantiation part too, as documented here:
Made custom activity and application Java class files, placed in Sources/Android.
/'Some manual configuration for the Projucers Android exporter was necessary:
Java Source code folders:
Source/Android
Custom Android Activity:
eu.selfhost.audiooffler.jucyfluttering.FlutteringActivity
Custom Android Application:
eu.selfhost.audiooffler.jucyfluttering.FlutteringApplication
Module Dependencies:
implementation project(':flutter')
Extra module's build.gradle content:
defaultConfig {
ndk {
// filter for architectures supported by Flutter
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
compileOptions {
// Flutter Android engine uses Java 8 features
sourceCompatibility 1.8
targetCompatibility 1.8
}
Custom settings.gradle content:
setBinding(new Binding([gradle: this]))
evaluate(new File(
settingsDir.parentFile.parentFile,
'fluttering/.android/include_flutter.groovy'
))
Android Theme:
@android:style/Theme.NoTitleBar
Projucer can't create / manipulate a gradle.properties file, but this is needed for Flutter
The file with the following content was manually placed at Builds/Android folder of this repository, it won't get overwritten by the Projucre, just do not delete it manually:
android.useAndroidX=true
android.enableJetifier=true
Made a custom App Delegate class, placed at Sources/iOS. This is an UIApplicationDelegate for running JUCE and Flutter in an iOS app. It's .mm File also has the START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE call to automatically start the JUCEApplication with this Delegate, as documented in JUCE/modules/juce_events/messages/juce_Initialisation.h. The delegate takes care of:
CocoaPods is needed for FLutter integration.
which pod), do so with sudo gem install cocoapodBuilds/iOS/Podfile), containing the following. The Projucer won't overwite it, just do not delete it manually.
platform :ios, '9.0'
flutter_application_path = '../../fluttering'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'Jucy Fluttering - App' do
install_all_flutter_pods(flutter_application_path)
end
In Projucer, some iOS export settings had to be configured:
$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
<plist>
<dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
</dict>
</plist>
No extra steps needed building. The project can be opened with Android Studio from the Projucer or by opening the Builds/Android project folder in Android Studio.
If dart support is enabled for the project in Android Studio, it even attaches the flutter debugger.
Else, while running / debugging, one may call flutter attach from terminal (first go to cd ./fluttering).
After saving / exporting with Projucer, the XCode Project can't simply be build as usual for JUCE projects. Two more steps are necassary:
pod install (first go to cd ./Builds/iOS).xcworkspace project and build that
While running / debugging from xCode, one may call flutter attach from terminal (first go to cd ./fluttering).
Check out the Flutter/dart:ffi documentation for the basic setup of accessing nativ C++ code from Flutter/dart.
Some examples can be found in Sources/JucyFlutteringInterop.h and the dart counterparts in fluttering/lib/juce_fluttering_interop.dart.
fluttering/lib/juce_fluttering_interop.dart.juce::Strings, JUCE has to return UTF-8 char* pointerstoRawUTF8, malloc and strcpy, see the example in EXTERN_C const char *getAppName() in Source/JucyFlutteringInterop.h, using the helper function const char *copyStringToUTF8(String juceString) from the same filefromUtf8 and call free on the returned Pointer<Utf8>, utilizing import package:ffi/ffi.dart. See tthe example in fluttering/lib/juce_fluttering_interop.dartProblem:
juce::Timer) or AudioCallback Threads (e.g. juce::AudioProcessor) won't run in the same isolate as Flutter/Dart UI.Solution: