rmbrone / flutter_audio_recorder

Flutter plugin that can support audio recording and level metering
MIT License
121 stars 150 forks source link

On Android using camera plugin and audio recorder cause permission issue and crash for the first launch #10

Closed iNima closed 4 years ago

iNima commented 4 years ago

Hi there,

I added the required permission in the AndroidManifest file but in my app I'm also using the camera plugin. So, as soon as the camera is initiated it askes two permissions. 1- access to camera 2- access to audio recording via mic

When I allow permission the app crashes. It happens even when I don't use flutter_audio_recorder at all, only adding the plugin in the pubspec.yaml is enough to see this exception when we allow permissions:

E/AndroidRuntime(17775): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=9796, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {....MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
E/AndroidRuntime(17775):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4398)
E/AndroidRuntime(17775):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4440)
E/AndroidRuntime(17775):    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
E/AndroidRuntime(17775):    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime(17775):    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime(17775):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
E/AndroidRuntime(17775):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(17775):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(17775):    at android.app.ActivityThread.main(ActivityThread.java:6718)
E/AndroidRuntime(17775):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17775):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(17775):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime(17775): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
E/AndroidRuntime(17775):    at com.zeno.flutter_audio_recorder.FlutterAudioRecorderPlugin.onRequestPermissionsResult(FlutterAudioRecorderPlugin.java:82)
E/AndroidRuntime(17775):    at io.flutter.app.FlutterPluginRegistry.onRequestPermissionsResult(FlutterPluginRegistry.java:194)
E/AndroidRuntime(17775):    at io.flutter.app.FlutterActivityDelegate.onRequestPermissionsResult(FlutterActivityDelegate.java:127)
E/AndroidRuntime(17775):    at io.flutter.app.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:137)
E/AndroidRuntime(17775):    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7616)
E/AndroidRuntime(17775):    at android.app.Activity.dispatchActivityResult(Activity.java:7466)
E/AndroidRuntime(17775):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4391)
E/AndroidRuntime(17775):    ... 11 more

I don't know why the crash happens in com.zeno.flutter_audio_recorder.FlutterAudioRecorderPlugin.onRequestPermissionsResult(FlutterAudioRecorderPlugin.java:82) although I didn't even import it in my class file!

(It works correctly on iOS by the way)

nikli2009 commented 4 years ago

Hi Nima, Thanks for reporting the issue, 0.5.4 should be ok.


I don't know why the crash happens in com.zeno.flutter_audio_recorder.FlutterAudioRecorderPlugin.onRequestPermissionsResult(FlutterAudioRecorderPlugin.java:82) although I didn't even import it in my class file!

After done some troubleshooting, It's quite interesting that I found that Flutter will register all the plugins for us after we install any new plugins(even without use them like you mentioned in the first post). ( you could find the Registrant in ./Android/app/src/main/java/io.flutter.plugins/GeneratedPluginRegistrant).

And the permission result callback in Android was registered along with the plugin(but this situation was not handled correctly in 0.5.3), that's why this issue was introduced.

Thanks Nik

iNima commented 4 years ago

Thanks @nikli2009 At the moment I switched to another plugin because of supporting aac on Android. By the way, thanks for fixing this issue.