I’m having an issue requesting audio recording permissions where FragmentOverlay::open() gets invoked, and the call on CallObjectMethod has a null argument from getCurrentActivity().get(). My code is not managed by projucer, but I’m attaching the thread and calling initialiseJUCE() correctly. What could cause this call to be null?
Did you find a resolution to this? I have a stock android project and am experiencing the same thing.
Here’s one of many stack traces from Google Play Console:
JNI DETECTED ERROR IN APPLICATION: obj == null
_JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, …)
sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/jni.h:617:5
juce::FragmentOverlay::open()
modules/juce_core/native/juce_JNIHelpers_android.cpp:742:32
juce::startAndroidActivityForResult(juce::LocalRef<_jobject*> const&, int, std::__ndk1::function<void (int, int, juce::LocalRef<_jobject*>)>&&)
modules/juce_core/native/juce_JNIHelpers_android.cpp:797:15
juce::FileChooser::Native::launch()
modules/juce_gui_basics/native/juce_FileChooser_android.cpp:165:13
buttonClicked(juce::Button*)
Here’s my current version of juce’s FragmentOverlay::open:
734 void FragmentOverlay::open()
735 {
736 auto* env = getEnv();
737
738 LocalRef<jobject> bundle (env->NewObject (AndroidBundle, AndroidBundle.constructor));
739 env->CallVoidMethod (bundle.get(), AndroidBundle.putLong, javaString ("cppThis").get(), (jlong) this);
740 env->CallVoidMethod (native.get(), AndroidFragment.setArguments, bundle.get());
741
742 LocalRef<jobject> fm (env->CallObjectMethod (getCurrentActivity().get(), AndroidActivity.getFragmentManager));
743 env->CallVoidMethod (native.get(), AndroidDialogFragment.show, fm.get(), javaString ("FragmentOverlay").get());
744 }
Seems this is related to another issue with the current activity:
We cannot reproduce this issue, or the one in getCurrentActivity().get() is null when requesting permission with a Projucer-generated Android project.
When you say:
I have a stock android project
does that mean, you’re not using the Projucer, like the original poster?
It’s possible that you’re missing some small detail in your build that the Projucer gets right. Since the Projucer is the only supported way to build Android projects at the moment, perhaps you could try examining a project generated by the Projucer to look for configuration options that differ from your project.
If you are using the Projucer, we will likely need to reproduce the problem locally so that we can debug it and find a robust solution. It would be helpful if you could provide a minimal Projucer project that demonstrates the problem, and let us know which Android version (ideally one of the emulator images) triggers the issue.
I did use the Projucer to create the project. I have no way to reproduce this behavior, only several hundred crash logs in Google Play Console. Things work as desired while testing.
