Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Android 10 #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Support for Android 10 #361

wants to merge 1 commit into from

Conversation

1nikolas
Copy link

@1nikolas 1nikolas commented Jul 4, 2020

Based on this post.
Moved ffmpeg binary to the libs folder and added android:extractNativeLibs = "true" to the manifest so it can copy itself into /data/app/{package_name}/lib/{arch}/ and then execute it from there (which is supported on Android 10).
The x86 binary doesn't work on Android 6+, and that's a separate bug (see here and here)

Fixes #343
Fixes #355
Fixes #360

@sidhuparas
Copy link

Hi @1nikolas,

Thanks you for coming out with an approach to fix it. I came across this issue today and saw your PR. I felt that this would work and this should've worked. But I am getting following error when I try this with Android 10:

CANNOT LINK EXECUTABLE "/data/app/com.my.app.debug-YuYsFFp_DMmblCEyt_UMBw==/lib/x86/libffmpeg.so": "/data/app/com.short.videos.debug-YuYsFFp_DMmblCEyt_UMBw==/lib/x86/libffmpeg.so" has text relocations (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23)

I tried it on an Emulator running Android 10. After researching, it seems that FFMpeg and Google both have refused to fix this Text relocations issue.

I just forked the library from your repo and imported it. Then gave a try. Am I doing something wrong?

Also, before it used to work on Android < 10. But now it's throwing the error in those versions as well:

  java.io.IOException: Cannot run program "/data/app/com.my.app.debug-TXqL44hB_UvrunVGGIUrFQ==/lib/arm/libffmpeg.so": error=2, No such file or directory

Looking forward to your response.

@1nikolas
Copy link
Author

1nikolas commented Jul 9, 2020

Hi @1nikolas,

Thanks you for coming out with an approach to fix it. I came across this issue today and saw your PR. I felt that this would work and this should've worked. But I am getting following error when I try this with Android 10:

CANNOT LINK EXECUTABLE "/data/app/com.my.app.debug-YuYsFFp_DMmblCEyt_UMBw==/lib/x86/libffmpeg.so": "/data/app/com.short.videos.debug-YuYsFFp_DMmblCEyt_UMBw==/lib/x86/libffmpeg.so" has text relocations (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23)

I tried it on an Emulator running Android 10. After researching, it seems that FFMpeg and Google both have refused to fix this Text relocations issue.

I just forked the library from your repo and imported it. Then gave a try. Am I doing something wrong?

Also, before it used to work on Android < 10. But now it's throwing the error in those versions as well:

  java.io.IOException: Cannot run program "/data/app/com.my.app.debug-TXqL44hB_UvrunVGGIUrFQ==/lib/arm/libffmpeg.so": error=2, No such file or directory

Looking forward to your response.

The emulator uses by default x86 architecture and it doesnt work on x86 on Android 6+ that way (as I already mentioned). As for the other error, you have to add these on your app build.gradle (so it forces arm64 devices to use the arm binary and x86_64 to use the x86 one)

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

@Ronnys
Copy link

Ronnys commented Jul 10, 2020

how can we use the new commit??

@1nikolas
Copy link
Author

how can we use the new commit??

You can find the fork on my account or you can click 1nikolas:master from here

@sidhuparas
Copy link

@1nikolas Thanks for the quick reply. I tried your suggestion and it worked for Android < 10. But when I tested it on Android 10, it gave me a long error (couldn't see full error). I know that to resolve the issue, I should provide that error but there came some fault in the device and I am fixing it. As soon as it goes up, I will post the trace here. Thank you for the time.

@Ahmed-Basalib10
Copy link

@1nikolas what did u mean by ffmpeg binary ?

@1nikolas
Copy link
Author

1nikolas commented Jul 14, 2020

@1nikolas what did u mean by ffmpeg binary ?

Pre build ffmpeg executables for each cpu architecture. This libary uses those to run ffmpeg (on the current commit its on the assets folder and on my commit its on the libs folder)

@SundaramKrishna
Copy link

SundaramKrishna commented Jul 16, 2020

this fix will be released ? or i have to pull from @1nikolas repository

@1nikolas
Copy link
Author

this fix will be released ? or i have to pull from @1nikolas repository

I don't think so. This repo is abandoned since 2016..

@arjun-6573
Copy link

Its working fine but unable to upload app on play store
getting issue This release is not compliant with the Google Play 64-bit requirement but after applying
ndk {
abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
play store allowing to publish but it's unable to load binary its always failing

@1nikolas
Copy link
Author

1nikolas commented Jul 19, 2020

Its working fine but unable to upload app on play store
getting issue This release is not compliant with the Google Play 64-bit requirement but after applying
ndk {
abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
play store allowing to publish but it's unable to load binary its always failing

Okay this is a problem I didn't predict. A workaround for this would be to keep the abifilters as you mentioned and copy libffmpeg.so from libs/x86 to libs/x86_64 and libffmpeg.so from libs/arm to libs/arm64. But this will make the apk size larger as it would have the library 4 times inside the apk.

Anyway to everyone reading this, this PR is a workaround and doesnt work 100% because this library is super old. Just use a newer ffmpeg library (which uses ndk) instead of trying to fix this one. Its not worth the time.

@sidhuparas
Copy link

@1nikolas Can you recommend a "newer ffmpeg library"? For some strange reason, I still can't get hold of my Android 10 phone. I will be looking to implement your fix otherwise I might go for a newer library.

@1nikolas
Copy link
Author

@1nikolas Can you recommend a "newer ffmpeg library"? For some strange reason, I still can't get hold of my Android 10 phone. I will be looking to implement your fix otherwise I might go for a newer library.

There are many libs but this seems to be the most popular. You can google "ffmpeg android github" to find more .

@sidhuparas
Copy link

@1nikolas Well, thank you. I migrated to that library's LTS support (for which min SDK is 21) and it's working perfectly on Android 10. Thank you! 🎉

@HungTDO
Copy link

HungTDO commented Jul 27, 2020

When I'm applied your code into my project, then I run project always recieved error: "ava.io.IOException: Cannot run program "/data/app/com.abc.xxx-eFkeAFz_FIOZAFRtph32mw==/lib/arm/libffmpeg.so": error=2, No such file or directory"?

@Herz3h
Copy link

Herz3h commented Jul 27, 2020

@HungTDO check this #361 (comment)

@HungTDO
Copy link

HungTDO commented Jul 28, 2020

@HungTDO check this #361 (comment)

It's worked! Thanks so much!

@Ahmed-Basalib10
Copy link

@1nikolas Well, thank you. I migrated to that library's LTS support (for which min SDK is 21) and it's working perfectly on Android 10. Thank you! 🎉

Can you explain how did you do that ?

@sidhuparas
Copy link

@Ahmed715 Just go to this repo. Find the gradle dependency to add. Just remember you need to use 4.3.1.LTS in the end instead of 4.3.2 if your project has minSDK as 21. The API's are similar. Directly using there are no callbacks and the code is synchronous so you need to manage multithreading on your own. I used Coroutines to achieve that. Check section 2.2 here.

@khacdat1994
Copy link

How to switch between android Q version and below? Thank. I'm read file from libs folder but not working

@1nikolas
Copy link
Author

How to switch between android Q version and below? Thank. I'm read file from libs folder but not working

My fix should work in all android versions. Whats the error?

@godhiepnt
Copy link

Its working fine but unable to upload app on play store
getting issue This release is not compliant with the Google Play 64-bit requirement but after applying
ndk {
abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
play store allowing to publish but it's unable to load binary its always failing

Okay this is a problem I didn't predict. A workaround for this would be to keep the abifilters as you mentioned and copy libffmpeg.so from libs/x86 to libs/x86_64 and libffmpeg.so from libs/arm to libs/arm64. But this will make the apk size larger as it would have the library 4 times inside the apk.

Anyway to everyone reading this, this PR is a workaround and doesn't work 100% because this library is super old. Just use a newer FFmpeg library (which uses ndk) instead of trying to fix this one. It's not worth the time.

Hi, @1nikolas Can you show me what the folders look like after copying?
Screen Shot 2020-08-24 at 4 53 50 PM
Screen Shot 2020-08-24 at 4 54 48 PM

It's unable to load binary. It's always failing

@1nikolas
Copy link
Author

@godhiepnt they way you did it, it should work. Whats the error? The file isn't copied in the app data libs?

@godhiepnt
Copy link

@godhiepnt did you add these to your gradle?

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

Yes. If in buildTypes , abiFilters "armeabi-v7a", "x86" it works great . But abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64' error :
E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@2526a
java.io.IOException: Cannot run program "/data/app/g3.videoeditor.videomakerwithmusic-bmB3e7UAy_hXWwAJ9h4Qrg==/lib/arm/libffmpeg.so": error=2, No such file or directory

Can you help me understand better?

@1nikolas
Copy link
Author

@godhiepnt try using these two abi filters only abiFilters "armeabi-v7a", "x86" and delete arm64 and x86_64 folders in libs. This should make it work on all 4 archs

@godhiepnt
Copy link

@godhiepnt try using these two abi filters only abiFilters "armeabi-v7a", "x86" and delete arm64 and x86_64 folders in libs. This should make it work on all 4 archs

This release is not compliant with the Google Play 64-bit requirement.
The following APKs or App Bundles are available to 64-bit devices, but they only have 32-bit native code:
Include 64-bit and 32-bit native code in your app. Use the Android App Bundle publishing format to automatically ensure that each device architecture receives only the native code it needs. This avoids increasing the overall size of your app.

@1nikolas Can you help me fix it?

@1nikolas
Copy link
Author

1nikolas commented Aug 25, 2020

@godhiepnt you have to copy contents of arm to arm64 and cotents of x86 to x86_64. And then you have to modify some code (on FileUtils.java line 59 you have to add 2 more else ifs according on how arch folders are named)

@krushnarathod
Copy link

solution work in debug mode , but when we generate sign apk ,through as error #360 java.io.IOException: Cannot run program "/data/app/com.test.maker--dN1llxm8vYjyFIC4I3iHA==/lib//libffmpeg.so": error=2, No such file or directory

@1nikolas
Copy link
Author

solution work in debug mode , but when we generate sign apk ,through as error #360 java.io.IOException: Cannot run program "/data/app/com.test.maker--dN1llxm8vYjyFIC4I3iHA==/lib//libffmpeg.so": error=2, No such file or directory

If you use "armeabi-v7a", "x86" you have to add them in debug too. See the first comments

@krushnarathod
Copy link

is there any solution for arm64-v8a x86_64 because when we fetch ffmpeg from lib folder it wont detect .so file, Through file not exist error.

@1nikolas
Copy link
Author

is there any solution for arm64-v8a x86_64 because when we fetch ffmpeg from lib folder it wont detect .so file, Through file not exist error.

did you add those?

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

@krushnarathod
Copy link

is there any solution for arm64-v8a x86_64 because when we fetch ffmpeg from lib folder it wont detect .so file, Through file not exist error.

did you add those?

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

Yes added it work fine with that. but using this it exclude arm64-v8a x86_64 , so there is no 64 bit arch. according to new google play policy apps published on Google Play will need to support 64-bit architectures

@1nikolas
Copy link
Author

is there any solution for arm64-v8a x86_64 because when we fetch ffmpeg from lib folder it wont detect .so file, Through file not exist error.

did you add those?

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

Yes added it work fine with that. but using this it exclude arm64-v8a x86_64 , so there is no 64 bit arch. according to new google play policy apps published on Google Play will need to support 64-bit architectures

Okay then remove these I mentioned and copy x86 files in the x86_64 folder and arm files to arm64 folder (I dont remember the exact folder names)

@krushnarathod
Copy link

is there any solution for arm64-v8a x86_64 because when we fetch ffmpeg from lib folder it wont detect .so file, Through file not exist error.

did you add those?

    buildTypes {
        release {
           [...]
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }

Yes added it work fine with that. but using this it exclude arm64-v8a x86_64 , so there is no 64 bit arch. according to new google play policy apps published on Google Play will need to support 64-bit architectures

Okay then remove these I mentioned and copy x86 files in the x86_64 folder and arm files to arm64 folder (I dont remember the exact folder names)

I did .but show the same issue

@1nikolas
Copy link
Author

@krushnarathod are you sure you used the correct folder names?

@krushnarathod
Copy link

@krushnarathod are you sure you used the correct folder names?

Yes ,folder name is correct

@1nikolas
Copy link
Author

@krushnarathod try mobile-ffmpeg lts version. I don't know how to fix your problem

@krushnarathod
Copy link

static String getFFmpeg(Context context) {

    String archFolder = "";

    if (CpuArchHelper.getCpuArch() == CpuArch.x86){
        archFolder = "x86";
    } else if (CpuArchHelper.getCpuArch() == CpuArch.ARMv7){
        archFolder = "arm";
    }

    return context.getApplicationInfo().nativeLibraryDir + "/" + ffmpegFileName;

// return context.getPackageResourcePath().replaceAll("/([^/]+)$", "/lib/") + archFolder + "/" + ffmpegFileName;
}

Changed in FileUtils.java class and it works

@Udhayarajan
Copy link

Udhayarajan commented Mar 30, 2021

Thanks for modifying this. By the way , How to add your commit in build,gradle like

implementation 'com.github.1nikolas:ffmpeg-android-java:master-SNAPSHOT'

is this correct? Another question will it works on Android 11 and Upcoming android 12?

@dmkenza
Copy link

dmkenza commented Mar 30, 2021

@Udhayarajan
This library not working with android 10.

Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10

Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

@1nikolas
Copy link
Author

@Udhayarajan you have to go to my profile, download my fork and import it manually to your project. But I haven't tested it with android 11 and 12. If you are going to upload your app on Playstore, just use mobile-ffmpeg with split apks.

@Udhayarajan
Copy link

@Udhayarajan
This library not working with android 10.

Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10

Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

It works on Android 11

@pintudhameliya123
Copy link

Hi, @1nikolas I still get below error while compiling this library..

java.io.IOException: Cannot run program "/data/app/com.test.maker--dN1llxm8vYjyFIC4I3iHA==/lib//libffmpeg.so": error=2, No such file or directory

@1nikolas
Copy link
Author

1nikolas commented Apr 2, 2021

Hi, @1nikolas I still get below error while compiling this library..

java.io.IOException: Cannot run program "/data/app/com.test.maker--dN1llxm8vYjyFIC4I3iHA==/lib//libffmpeg.so": error=2, No such file or directory

What Android are you on? It's only tested on Android 10. Also did you add android:extractNativeLibs = "true" to your manifest?

@pintudhameliya123
Copy link

pintudhameliya123 commented Apr 2, 2021

Already add android:extractNativeLibs = "true" in the manifest

@Udhayarajan
Copy link

@pintudhameliya123 try disabling offline gradle build and rebuild project. Also try

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

It is working on Android 11 also tested

@NoVaTin202
Copy link

I got this error when writing ffmpeg from assets to lib on android 10. Is anyone showing me the solution.
It reports: /error while writing: java.io.FileNotFoundException: /data/app/com.videomaker.photovideo.pro-409-c8LVUYlrDdKTTadGIA==/lib/arm/libffmpeg.so: open failed: EACCES (Permission denied)

@Ahmed-Basalib10
Copy link

@Udhayarajan
This library not working with android 10.
Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10
Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

It works on Android 11

Yes it is working but what about the size of ur app , mine is so large after i used this lib

@Udhayarajan
Copy link

@Udhayarajan
This library not working with android 10.
Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10
Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

It works on Android 11

Yes it is working but what about the size of ur app , mine is so large after i used this lib

Yes mine too. 30MB to 75MB which is huge. Try to split apks based on abis or use AAB if use Google play store to publish

@Ahmed-Basalib10
Copy link

Ahmed-Basalib10 commented Jul 29, 2021

@Udhayarajan
This library not working with android 10.
Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10
Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

It works on Android 11

Yes it is working but what about the size of ur app , mine is so large after i used this lib

Yes mine too. 30MB to 75MB which is huge. Try to split apks based on abis or use AAB if use Google play store to publish

Also it supports only android level 24 and above , is there any way to make it support lower versions also from 21 level

@Udhayarajan
Copy link

@Ahmed-Basalib10 use LTS version btw, FFMPEG is archived use FFmpegKit instead.

@csandhack
Copy link

@Udhayarajan
This library not working with android 10.
Use this
https://github.com/tanersener/mobile-ffmpeg
Only way for using FFmpeg with android 10
Library is very big, but you can generate that you need. And use apk split also.

splits {

    abi {
        // Enables building multiple APKs per ABI.
        enable true
        reset()
        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
       
    }
}

It works on Android 11

Yes it is working but what about the size of ur app , mine is so large after i used this lib

Yes mine too. 30MB to 75MB which is huge. Try to split apks based on abis or use AAB if use Google play store to publish

I need to add this library natively , how do I do that, can you please tell me the steps to add it in my application natively and run on android 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet