FFmpeg-Android icon indicating copy to clipboard operation
FFmpeg-Android copied to clipboard

Permission denied running version command when targeting Android Q

Open darrinps opened this issue 6 years ago • 40 comments

Not sure if it's because I am running Android Q beta, or I'm doing something wrong but I am getting the following:

2019-07-26 12:29:01.320 24329-24408/com.android.testffmpeg E/FFmpeg: Exception while trying to run: [/data/user/0/com.android.testffmpeg/files/ffmpeg, -version] java.io.IOException: Cannot run program "/data/user/0/com.android.testffmpeg/files/ffmpeg": error=13, Permission denied at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050) at nl.bravobit.ffmpeg.ShellCommand.run(ShellCommand.java:15)

All I am doing is calling this function:

`
private fun versionFFmpeg() { FFmpeg.getInstance(TestFFmpegApplication.instance.applicationContext) .execute(arrayOf("-version"), object : ExecuteBinaryResponseHandler() { override fun onSuccess(message: String?) { Timber.d(message) }

            override fun onProgress(message: String?) {
                Timber.d(message)
            }
        })

}

`

The only setup I have in the code is this:

implementation 'nl.bravobit:android-ffmpeg:1.1.7'

Can anyone see what it is I am missing, or perhaps there is an issue running on Android Q?

darrinps avatar Jul 26 '19 17:07 darrinps

Looks like it's Q. If I build and run your sample app verbatim, it works, but when I change the compile and target SDK to be 29....crash. Same as I see in my app. So I think this looks to be a fairly high bug given Q will be released shortly.

darrinps avatar Jul 26 '19 18:07 darrinps

Tried this on Q emulator, system-images\android-29\google_apis\x86, and it simply worked.

alexcohn avatar Aug 07 '19 08:08 alexcohn

I have updated the Q emulator (now it is [google/sdk_gphone_x86/generic_x86:10/QPP6.190730.005.B1/5775370:userdebug/dev-keys]), and the it does not permit to run ffmpeg from the files directories anymore. Or maybe the trigger is that I set targetSdk=29.

Actually, this is a documented change.

The fix is to move ffmpeg from assets to jniLibs.

alexcohn avatar Aug 11 '19 11:08 alexcohn

Someone has solution to run ffmpeg commands in android Q its urgent??

desaibijal avatar Dec 23 '19 09:12 desaibijal

Any updates on this?

kartik1225 avatar Dec 27 '19 20:12 kartik1225

Hi, I didn't try it myself but probably you can fix it with adding

android:requestLegacyExternalStorage="true"

to application in AndroidManifest.xml

kazemihabib avatar Dec 27 '19 20:12 kazemihabib

No, it still does not work

kartik1225 avatar Dec 27 '19 20:12 kartik1225

Try this library I just tested it on a physical device running Android Q (android 10)

WassimErriha avatar Jan 09 '20 19:01 WassimErriha

@WassimErriha Thanks, it worked.

PO15ON avatar Feb 15 '20 14:02 PO15ON

Any updates on this?

Or is this the end of this library?

Aditya94A avatar Feb 27 '20 04:02 Aditya94A

I found solution on this issue. https://issuetracker.google.com/issues/128554619

exec() no longer works on files within the application home directory, it continues to be supported for files within the read-only /data/app directory. In particular, it should be possible to package the binaries into your application's native libs directory and enable android:extractNativeLibs=true, and then call exec() on the /data/app artifacts. A similar approach is done with the wrap.sh functionality, documented at https://developer.android.com/ndk/guides/wrap-script#packaging_wrapsh .

It works well on my project(tested on Pixel 3a XL android Q)

Le-Dinh-Nam avatar Mar 08 '20 03:03 Le-Dinh-Nam

I have updated the Q emulator (now it is [google/sdk_gphone_x86/generic_x86:10/QPP6.190730.005.B1/5775370:userdebug/dev-keys]), and the it does not permit to run ffmpeg from the files directories anymore. Or maybe the trigger is that I set targetSdk=29.

Actually, this is a documented change.

The fix is to move ffmpeg from assets to jniLibs.

I have create jniLibs folder then move the lib from assets,but still not work, Is there something i miss?

AmioLee avatar Mar 12 '20 03:03 AmioLee

I have create jniLibs folder then move the lib from assets,but still not work, Is there something i miss?

It's much more than simply renaming some folders, see https://github.com/bravobit/FFmpeg-Android/pull/130

alexcohn avatar Mar 12 '20 07:03 alexcohn

Why hasn't this been merged yet, even Android 11 is about be released, has this project been abandoned?

vincent-paing avatar Apr 08 '20 11:04 vincent-paing

Just change targetSdkVersion 29 to 28 in build.gradle

It worked for me.

pratikbutani avatar May 05 '20 04:05 pratikbutani

@pratikbutani not a solution that works on higher android versions

kibotu avatar May 05 '20 13:05 kibotu

@kibotu It's working on higher version too. I have checked on Android 10.

pratikbutani avatar May 06 '20 01:05 pratikbutani

not working for me

SnehaDZ avatar May 11 '20 06:05 SnehaDZ

NOT WORKING FOR ME TOO. Have anyone found an answer to this problem?

aliraza96 avatar May 12 '20 05:05 aliraza96

@SnehaDZ @aliraza96 if you can set targetSdkVersion less than 29, your app will continue to work even on Android 11 (a.k.a. Android R). Note that this does not prevent you from using the new Android Q APIs in your code.

But if you want to switch to 29, you can try my fork. In the long run, I would recommend to switch to another library, even though this means that your code must be changed: with every upgrade, Android becomes less open to running executables in the context of an app.

alexcohn avatar May 12 '20 07:05 alexcohn

any update ?

Ahmed-Basalib10 avatar Jul 18 '20 12:07 Ahmed-Basalib10

still unrepaired

kdsrsl avatar Jul 20 '20 11:07 kdsrsl

any update?

iamkdblue avatar Jul 22 '20 07:07 iamkdblue

We're using this library instead now, which is still maintained actively

https://github.com/tanersener/mobile-ffmpeg

vincent-paing avatar Jul 22 '20 08:07 vincent-paing

You can take a look on my approach on the original repo. I basically moved ffmpeg to the libs folder and renamed it to libffmpeg.so (should start with lib and end with .so in order for this to work). Then I added android:extractNativeLibs = "true" to the manifest so the binary is moved into data/app/{package_name}/lib/{arch}/, where it can me executed on Android 10.

There is a problem with this though. You have to put the binaries 4 times in the apk (if you want an apk that supports all architectures). The only way to have the binaries 2 times is to build the apk for arm and x86 only (so it can use the x86 binary on x64 and arm binary for arm64). But then playstore wont let you upload your app because it doesn't have native x64 support.

1nikolas avatar Jul 23 '20 17:07 1nikolas

I have updated the Q emulator (now it is [google/sdk_gphone_x86/generic_x86:10/QPP6.190730.005.B1/5775370:userdebug/dev-keys]), and the it does not permit to run ffmpeg from the files directories anymore. Or maybe the trigger is that I set targetSdk=29.

Actually, this is a documented change.

The fix is to move ffmpeg from assets to jniLibs.

how can I move from assets to JNI libs?

AamirNaseer1 avatar Aug 05 '20 12:08 AamirNaseer1

use this implementation 'com.arthenica:mobile-ffmpeg-full:4.3.1.LTS'

iamkdblue avatar Aug 05 '20 12:08 iamkdblue

use this implementation 'com.arthenica:mobile-ffmpeg-full:4.3.1.LTS'

I tried this, ffmpeg -version hits onFailure. do I need to do load library with this version. The 0.3.2 from writingminds required it.

plazar99 avatar Aug 17 '20 21:08 plazar99

@plazar99 normally, the library loads its native part by itself. But your mileage may vary.

alexcohn avatar Aug 17 '20 21:08 alexcohn

I just rebuild it for sdktarget 28, no difference. I'm afraid I'm missing something fundamental here.

plazar99 avatar Aug 18 '20 00:08 plazar99