rmbrone / flutter_audio_recorder

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

Issue while compiling for Android #5

Closed iNima closed 4 years ago

iNima commented 4 years ago

Hi @nikli2009

The plugin works flawlessly on iOS but it does not compile on Android for my app. The minSdkVersion in my app is 23 and the app has been migrated to support AndroidX

android.useAndroidX=true
android.enableJetifier=true

My Flutter version is 1.9.1+hotfix.6

The error that I got while compiling the app on Android was this:

/Users/iNima/.pub-cache/hosted/pub.dartlang.org/flutter_audio_recorder-0.4.8/android/src/main/java/com/zeno/flutter_audio_recorder/FlutterAudioRecorderPlugin.java:10: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
                             ^
  symbol:   class ActivityCompat
  location: package android.support.v4.app
/Users/iNima/.pub-cache/hosted/pub.dartlang.org/flutter_audio_recorder-0.4.8/android/src/main/java/com/zeno/flutter_audio_recorder/FlutterAudioRecorderPlugin.java:11: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
                                 ^
/Users/iNima/.pub-cache/hosted/pub.dartlang.org/flutter_audio_recorder-0.4.8/android/src/main/java/com/zeno/flutter_audio_recorder/FlutterAudioRecorderPlugin.java:62: error: cannot find symbol
    return ContextCompat.checkSelfPermission(registrar.context(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
           ^
  symbol:   variable ContextCompat
  location: class FlutterAudioRecorderPlugin
/Users/iNima/.pub-cache/hosted/pub.dartlang.org/flutter_audio_recorder-0.4.8/android/src/main/java/com/zeno/flutter_audio_recorder/FlutterAudioRecorderPlugin.java:104: error: cannot find symbol
    ActivityCompat.requestPermissions(registrar.activity(), new String[]{Manifest.permission.RECORD_AUDIO}, MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
    ^
  symbol:   variable ActivityCompat
  location: class FlutterAudioRecorderPlugin
4 errors
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************

Could you please check this issue as well? Thanks Nima

nikli2009 commented 4 years ago

Hi @iNima, This plugin hasn't been migrated to AndroidX at this point, alternatively I think we could set enableJetifier to false in our projects to let Gradle still use the old Android support libs to compile this plugin(or any other plugin that hasn't provide AndroidX support yet).

android.useAndroidX=true
android.enableJetifier=false

We will eventually migrate this plugin to AndroidX, and then update the major version of this plugin.

Hope this workaround works for you :)

iNima commented 4 years ago

Hi @nikli2009 Unfortunately, setting enableJetifier to false didn't work for me. By doing that our app receives this error without any more details (even by running flutter run -v):

[        ] *******************************************************************************************
[   +1 ms] The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
[        ] See https://goo.gl/CP92wY for more information on the problem and how to fix it.
[        ] *******************************************************************************************

Gradle task assembleDebug failed with exit code 1

Based on this document the reason for setting enableJetifier to true is to be able to add plugins that have not yet migrated to AndroidX. https://flutter.dev/docs/development/androidx-migration#what-if-my-app-is-migrated-to-androidx-but-not-all-of-the-plugins-i-use

So, now even I think the error messages I sent you in the first post might not be related to AndroidX at all. It seems that it's related to permission issues. Although I saw you have done some changes in the Android side related to the permission in 0.4.9, it still shows me the same error message as the first post above.

I hope there would be a solution for this otherwise I need to use another plugin and write everything from scratch related to the audio recording part of the app.

Please let me know if I need to test it in another way. Thanks.

nikli2009 commented 4 years ago

Hi @iNima , my apology for all the troubles. To reproduce the issue, I was using 1.9.1+hotfix.6 to create a new flutter application with AndroidX support enabled (using Android Studio), then add this plugin, then run flutter build apk, the issue was reproduced. and then after that I set enableJetifier to false to make this finally works.

  1. Could you provide your gradle version and would be better if paste build.gradle(the one under ./Android folder), with these information I can do more troubleshooting.

  2. And it will be better if you could create a new flutter application just for testing and trying to integrate this plugin. If it doesn't works, please let me know.

(If all of these doesn't work, we will add AndroidX support later.)

nikli2009 commented 4 years ago

Hi @iNima Just released AndroidX version(0.5.0), hope this build works for you.

In AndroidX project, use 0.5.x In non-AndroidX project, use0.4.9

ps: As it's beta version(0.x.x), the middle number will be treated as Major Version, so for non-AndroidX project, it is still safe if marked the version ^0.4.9 in yaml. It won't automatically upgrade to 0.5.x.

iNima commented 4 years ago

Hi @nikli2009 Thanks a lot for this change. It works now in an AndroidX enabled project.

I found two more issues which I think would be better to create separate issue cards for them.

I think this issue card can be closed. Thanks Nima