EliteMasterEric / extension-ffmpeg

An OpenFL extension which provides support for multimedia files on native platforms.
MIT License
18 stars 5 forks source link

[BUILD] Fixes for Android toolchain #19

Open ghost opened 2 years ago

ghost commented 2 years ago

Hi , i have been doing a script (using your build_linux64 script as a base) to build the ffmpeg libs for android, here it is if its usefull to you (yes i tested it with ndk r23c)

https://github.com/Randomxdp/extension-ffmpeg/blob/master/lib.src/build_android64.sh

i didnt test building the extension yet but take this script that builds the ffmpeg libs for android

ghost commented 2 years ago

change it at your will, organize it, make it cleaner, its all yours

EliteMasterEric commented 2 years ago

This is great! I can test with this a bit (I have an Android device) and if it works well I can make a pull request to add it (which should give you credit).

ghost commented 2 years ago

This is great! I can test with this a bit (I have an Android device) and if it works well I can make a pull request to add it (which should give you credit).

thats great!, the bad thing is that it looks like we cant use openssl without compiling openssl

ghost commented 2 years ago

just add the ndk llvm toolchain path to NDK_DIR in the script and it should be working

ghost commented 2 years ago

Hows it going?

EliteMasterEric commented 2 years ago

@Randomxdp I attempted to adapt the script to build to Android from a Linux machine and encountered this error:

~/Documents/Programming/Haxe/extension-ffmpeg/lib.src/ffmpeg ~/Documents/Programming/Haxe/extension-ffmpeg/lib.src
~/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang is unable to create an executable file.
C compiler test failed.

Here is the script I wrote: https://github.com/MasterEric/extension-ffmpeg/blob/build/android/lib.src/build_linux2android64.sh

I'm not sure what the root issue is, but I will note that the documentation for Lime clarifies that NDK r15c (and no later) must be used to compile for Android. Further research indicates the reason being that r16 removes G++ support (and only includes the Clang compiler). Will have to test further, but if you happen to have access to a Linux machine than experimentation from you would be greatly appreciated.

To the best of my knowledge, as long as SOMEONE can successfully generate an NDLL, that NDLL can be redistributed, and only needs to be rebuilt if the code in the project/common folder is updated (which at this stage in development is sadly going to be frequent), and the NDLL does not need rebuilding if the Haxe code updates.

ghost commented 2 years ago

@Randomxdp I attempted to adapt the script to build to Android from a Linux machine and encountered this error:

~/Documents/Programming/Haxe/extension-ffmpeg/lib.src/ffmpeg ~/Documents/Programming/Haxe/extension-ffmpeg/lib.src
~/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang is unable to create an executable file.
C compiler test failed.

Here is the script I wrote: https://github.com/MasterEric/extension-ffmpeg/blob/build/android/lib.src/build_linux2android64.sh

I'm not sure what the root issue is, but I will note that the documentation for Lime clarifies that NDK r15c (and no later) must be used to compile for Android. Further research indicates the reason being that r16 removes G++ support (and only includes the Clang compiler). Will have to test further, but if you happen to have access to a Linux machine than experimentation from you would be greatly appreciated.

To the best of my knowledge, as long as SOMEONE can successfully generate an NDLL, that NDLL can be redistributed, and only needs to be rebuilt if the code in the project/common folder is updated (which at this stage in development is sadly going to be frequent), and the NDLL does not need rebuilding if the Haxe code updates.

Hmm thats weird, i tried my script on windows and on termux using the r23c ndk which you should be able to download standalone (for termux i got one with llvm compiled for aarch64) and both worked, you should also look at the build log to find some clues

ghost commented 2 years ago

Also if we wanted to make it use gcc the script would need a rewrite to work with gcc

ghost commented 2 years ago

But since fnf android workflows work just fine with ndk r21e i think it would not be necessary

EliteMasterEric commented 2 years ago

But since fnf android workflows work just fine with ndk r21e i think it would not be necessary

I don't understand that since the documentation (and forums) say that Lime can't build with r16 or later. Please experiment though.

I will note that getting lime rebuild extension-ffmpeg android to complete is not an insignificant step. Please try to get that tested if you can.

ghost commented 2 years ago

I don't understand that since the documentation (and forums) say that Lime can't build with r16 or later. Please experiment though.

That isnt on the docs but it looks like it can build with ndk r21e with github actions, take a look at this run for example

https://github.com/MAJigsaw77/FNF-PsychEngine-With-Android-Support/runs/7701377710?check_suite_focus=true

I will note that getting lime rebuild extension-ffmpeg android to complete is not an insignificant step. Please try to get that tested if you can.

I know how important it is to test that and i will as soon as i can

ghost commented 2 years ago

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

EliteMasterEric commented 2 years ago

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

Can you report on what errors are occurring? I can't test the Android build because I don't have FFmpeg built yet.

EliteMasterEric commented 2 years ago

I have made some progress by creating a new build script based of this one, as well as running make clean before the build step.

https://gist.github.com/begeekmyfriend/6aa63a4d434daa53e7e8a6ff8ab6a00a

Will let you know how things progress and if I can create a build.

ghost commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

EliteMasterEric commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

One thread I found mentioned they solved it by installing and using NDK15

When I use NDK15, I get the following error that I haven't been able to solve (might have different results on Windows):

../lib.src/ffmpeg/libavutil/timer.h:38:31: fatal error: linux/perf_event.h: No such file or directory

include <linux/perf_event.h>

ghost commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

One thread I found mentioned they solved it by installing and using NDK15

When I use NDK15, I get the following error that I haven't been able to solve (might have different results on Windows):

../lib.src/ffmpeg/libavutil/timer.h:38:31: fatal error: linux/perf_event.h: No such file or directory

include <linux/perf_event.h>

after puting in the r15c ndk the previous error was gone but now we have a new one (on windows)

the error is that it basically cant find any of the .h files in your repo for some reason ( like common/Codec.h, common/Core.h, etc ) , im gonna try seeing whats the issue and i will keep you updated

MAJigsaw77 commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

When you rebuild at the end of android put -DHXCPP_ARM64

MAJigsaw77 commented 2 years ago

To fix that issue

ghost commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

When you rebuild at the end of android put -DHXCPP_ARM64

k

ghost commented 2 years ago

the error is: Please set one of the architectures, eg HXCPP_ARM64, HXCPP_X86, ...

after some testing ndk r21e is the latest one that can work with lime without issues and also work with the script correctly, i also tried building the extension, but since i dont know how to mod build.xml it dropped some errors, all i would need is you to add support for android in build.xml in the project folder

When you rebuild at the end of android put -DHXCPP_ARM64

that made ndk r21e work just fine

MAJigsaw77 commented 2 years ago

Just use r21e then

ghost commented 2 years ago

Just use r21e then

i built ffmpeg and tried to build extension-ffmpeg using ndk r21e but got .h error