tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.85k stars 787 forks source link

Permission Denied error in Android 10 #644

Closed passenger-earth closed 3 years ago

passenger-earth commented 3 years ago

This issue has already been covered here and the proposed solution is to use android:requestLegacyExternalStorage="true" in the android manifest file. It does solve the problem for Android 10 Api level 29.

But in the android documentation it says that starting from Android 11 , android:requestLegacyExternalStorage="true" attribute will be ignored by the system and therefore this will no longer work for Android 11.

Is there a better way to get across this error. I get the error Permission Denied , only when i change the targetSdk version to 29 and run it on Android 10 devices. The same code runs absolutely fine when i change the targetSdk version to 28 and run it on Android 10. This issue down't occur for lower Android versions.

I hope someone looks into this! Thanks..

mvxGREEN commented 3 years ago

@passenger-earth I ran into the same issue, and I believe it is because Android removed execute permissions within an app's home directory, for apps targeting SDK 29+. See: https://developer.android.com/about/versions/10/behavior-changes-10#execute-permission

Android's recommended workaround is to include the library as an embedded binary in the app's APK. I simply downloaded the library I needed as an .AAR file, put it into my project libs folder, added libs to my project-level gradle as follows: allprojects { repositories { ... flatDir { dirs 'libs' } } }

And finally, within in the app-level gradle, I replaced my old dependency with: implementation(name:'mobile-ffmpeg-full-4.4', ext:'aar')

Hope this works for you too!

passenger-earth commented 3 years ago

@mvxGREEN I don't know how to do this. Can you kindly guide me on how to download an .AAR file for this library?

Thank you so much!

mvxGREEN commented 3 years ago

Sure, at the very bottom of this page you'll find a bunch of downloadable files: https://github.com/tanersener/mobile-ffmpeg/releases

You're probably going to want the one called "mobile-ffmpeg-full-4.4.aar" unless you know for a fact you don't need the full functionality of the library.

Download the file. Then open your project in android studio, and navigate to your libs folder. To find this from within Android Studio, you need to change your project view from "Android" to "Project" via the drop-down menu (found directly below the 'File' button). At this point you should see your project's root directory & a directory called "External Libraries". Open the root directory, then open 'app' directory, where you should see dirs such as src, debug, release, etc. If you don't see a one called "libs" simply add it, and stick in the AAR you downloaded. Viola!

Just don't forget to change the dependencies afterwards.

passenger-earth commented 3 years ago

Hey , i did all the steps. downloaded the "mobile-ffmpeg-full-4.4.aar" file , put it in the Project>app>libs folder, then replaced the old dependency and also added the allprojects { repositories { ... flatDir { dirs 'libs' } } } in the gradle file. But it doesn't seem to solve the error. I still need to use android:requestLegacyExternalStorage="true" in the AndroidManifest to make it work in Android 10 with the targetSdk set to 29. If i remove the android:requestLegacyExternalStorage="true" attribute , the app stops working on Android 10.

I read the documentation that you linked above and it does say that the apps will only load binaries that are embedded in the apps Apk. I think i am doing something wrong , can you help me figure it out?

Thanks a lot for your kind support!

mvxGREEN commented 3 years ago

Does it solve the problem when you set targetSdkVersion to 30?

After your response I went back and saw, much to my embarrassment, I still had android:requestLegacyExternalStorage="true" BUT after removing that attribute and re-building & running, my solution still appears to work. Quite a rollercoaster!

Could you show the exact error message you're getting, and what call you are making that results in the error? I recall its a pretty short error code, but it would help those who haven't seen it potentially jump in.

passenger-earth commented 3 years ago

I got the "Permission Denied" and sometimes "No such files or directory" errors . After changing the targetSdk and compileSdk to 30 and running the app in Android 11 , it finally worked , even after removing the android:requestLegacyExternalStorage="true" from the Android Manifest. Previously I was testing on Android 10 . For running the app on Android 10 the android:requestLegacyExternalStorage="true" attribute is required even if you add the .AAR file to your libs folder. But now it also works on Android 11 just fine.

Thanks to @mvxGREEN for helping me. You have been very kind.