media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
916 stars 132 forks source link

[Bug Report] Unable to build iOS & package:flutter_ffmpeg_kit compatibility on Android #159

Closed Holofox closed 1 year ago

Holofox commented 1 year ago

Command:

flutter build ios --release -t ./lib/main.dart --no-codesign

Logs for iOS:

ERROR: No pubspec.lock was found: ENV["PWD"] = "/"
[!] Failed to load 'media_kit_native_event_loop' podspec: 
[!] Invalid `media_kit_native_event_loop.podspec` file: ERROR: No pubspec.lock was found: ENV["PWD"] = "/".

 #  from /Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_native_event_loop/ios/media_kit_native_event_loop.podspec:23
 #  -------------------------------------------
 #    if pubspec_lock_path == ''
 >      abort(
 #        sprintf('ERROR: No pubspec.lock was found: ENV["PWD"] = "%s"', ENV["PWD"])
 #  -------------------------------------------

##[error]The process '/usr/local/lib/ruby/gems/3.0.0/bin/pod' failed with exit code 1
##[error]The 'pod' command failed with error: The process '/usr/local/lib/ruby/gems/3.0.0/bin/pod' failed with exit code 1

Command:

flutter build apk --release -t lib/main.dart 

Logs for Android:

* What went wrong:
Execution failed for task ':app:mergeReleaseNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
   > 2 files found with path 'lib/x86/libavcodec.so' from inputs:
      - /Users/runner/.gradle/caches/transforms-3/179932a1e5526170ae637b254bf3c84e/transformed/jetified-video-x86.jar
      - /Users/runner/.gradle/caches/transforms-3/5f839fdc7e39313bb907a21151c1d4b2/transformed/jetified-ffmpeg-kit-min-gpl-5.1/jni
     If you are using jniLibs and CMake IMPORTED targets, see
     https://developer.android.com/r/tools/jniLibs-vs-imported-targets

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8m 1s
Running Gradle task 'assembleRelease'...                          481.5s

Flutter:

2023-04-25T05:30:26.0766540Z [!] Flutter (Channel unknown, 3.7.11, on macOS 12.6.5 21G531 darwin-x64, locale en)
2023-04-25T05:30:26.0785230Z     ! Flutter version 3.7.11 on channel unknown at /Users/runner/dev/flutter
2023-04-25T05:30:26.0792570Z       Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
2023-04-25T05:30:26.0793730Z       If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
2023-04-25T05:30:26.0797720Z     ! Unknown upstream repository.
2023-04-25T05:30:26.0798680Z       Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
2023-04-25T05:30:33.7288570Z [!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
2023-04-25T05:30:33.7290080Z     ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
2023-04-25T05:30:33.7296680Z [✓] Xcode - develop for iOS and macOS (Xcode 14.2)
2023-04-25T05:30:33.7297590Z [✓] Chrome - develop for the web
2023-04-25T05:30:33.7298040Z [!] Android Studio (not installed)
2023-04-25T05:30:34.7372210Z [✓] Connected device (2 available)
2023-04-25T05:30:34.7374930Z [✓] HTTP Host Availability

Dependencies:

media_kit: ^0.0.6
media_kit_video: ^0.0.8
media_kit_native_event_loop: ^1.0.3
media_kit_libs_android_video: ^1.0.1
media_kit_libs_ios_video: ^1.0.4
sunilguptasg commented 1 year ago
[!] CocoaPods could not find compatible versions for pod "media_kit_video":
  In Podfile:
    media_kit_video (from `.symlinks/plugins/media_kit_video/ios`)

... Error output from CocoaPods: ↳ media_kit: WARNING: package:media_kitlibs not found x client.h x render.h x render_gl.h x stream_cb.h media_kit: WARNING: package:media_kitlibs not found

=========

[✓] Flutter (Channel stable, 3.7.9, on macOS 13.3.1 22E261 darwin-arm64, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.77.3) [✓] Connected device (3 available) [✓] HTTP Host Availability

birros commented 1 year ago

Can you give us the version and location of pod please?

$ readlink -f $(which pod)
/usr/local/Cellar/cocoapods/1.12.1/bin/pod
$ pod --version
1.12.1
alexmercerind commented 1 year ago

On Android, the two shared libraries between media_kit & ffmpeg_kit_flutter seem to be conflicting in your case. Let's see if there's something that can be done, without requiring a specialized media_kitlibs*** package.

birros commented 1 year ago

And also the current location:

$ pwd

ERROR: No pubspec.lock was found: ENV["PWD"] = "/"

In short, the podspec in media_kit_native_event_loop looks for the pubspec.lock by recursively searching for it in the parent folders. The current folder seems invalid.

Holofox commented 1 year ago

@birros,

++ which pod
+ readlink -f /usr/local/lib/ruby/gems/3.0.0/bin/pod
/usr/local/lib/ruby/gems/3.0.0/bin/pod
+ pod --version
1.12.0
++ pwd
+ echo /Users/runner/work/1/s
/Users/runner/work/1/s

@alexmercerind, I understand that in my case there is a dependency conflict with video_editor, which uses ffmpeg_kit_flutter_min_gpl. I'll think about what can be done, then this is not a problem with the media_kit package.

Holofox commented 1 year ago

@alexmercerind, based on https://github.com/arthenica/ffmpeg-kit/issues/721 and https://github.com/arthenica/ffmpeg-kit/issues/722, I was able to get around the problem, but I ran into another one https://github.com/arthenica/ffmpeg-kit/issues/461. A very interesting case.

packagingOptions {
    // FFMpeg
    pickFirst 'lib/**/libc++_shared.so'
    pickFirst 'lib/**/libavcodec.so'
    pickFirst 'lib/**/libswscale.so'
    pickFirst 'lib/**/libavformat.so'
    pickFirst 'lib/**/libavutil.so'
    pickFirst 'lib/**/libavdevice.so'
    pickFirst 'lib/**/libavfilter.so'
    pickFirst 'lib/**/libswresample.so'
}

That is, I can't use ffmpeg_kit_flutter_min_gpl in my project.

MissingPluginException(No implementation found for method ffmpegSession on channel flutter.arthenica.com/ffmpeg_kit)]
birros commented 1 year ago

For iOS, since you apparently use a CI, can you share the configuration file please?

sunilguptasg commented 1 year ago

FYI - the build succeeds for macOS as target, but fails for ios. Do you need any specific information that can help get to the issue?

Holofox commented 1 year ago

For iOS, since you apparently use a CI, can you share the configuration file please?

I am using MS App Center, here is my application build process:

#!/usr/bin/env bash

# Fail if any command fails
set -ex

# Default values
PROJECT_DIR="$(dirname "$(pwd)")"

echo "##[section]: Install Flutter SDK"
mkdir ~/dev && cd "$_"
git clone -b 3.7.11 --depth 1 https://github.com/flutter/flutter.git
PATH="$(pwd)"/flutter/bin:$PATH
export PATH

echo "##[section]: Validate Flutter SDK"
flutter doctor

echo "##[section]: Go to project directory"
cd "$PROJECT_DIR"

echo "##[section]: Run code generators & build project"
flutter pub get packages
flutter packages pub run build_runner build --delete-conflicting-outputs

echo "##[section]: Start build"
flutter build ios --release -t ./lib/main.dart --no-codesign
Holofox commented 1 year ago

That is, I can't use ffmpeg_kit_flutter_min_gpl in my project.

@alexmercerind, do you have any idea why the media_kit_libs_android_video affects ffmpeg_kit_flutter_min_gpl?

ffmpeg_kit_flutter_min_gpl: ^5.1.0
media_kit_libs_android_video: ^1.0.1
packagingOptions {
    pickFirst 'lib/**/libc++_shared.so'
    pickFirst 'lib/**/libavcodec.so'
    pickFirst 'lib/**/libswscale.so'
    pickFirst 'lib/**/libavformat.so'
    pickFirst 'lib/**/libavutil.so'
    pickFirst 'lib/**/libavdevice.so'
    pickFirst 'lib/**/libavfilter.so'
    pickFirst 'lib/**/libswresample.so'
}

When I call:

import 'package:ffmpeg_kit_flutter_min_gpl/ffmpeg_kit.dart';

FFmpegKit.execute('');
The following MissingPluginException was thrown while activating platform stream on channel flutter.arthenica.com/ffmpeg_kit_event:
MissingPluginException(No implementation found for method listen on channel flutter.arthenica.com/ffmpeg_kit_event)

I couldn't do anything to fix the issue and get them to work together. Separately, the dependencies work fine.

alexmercerind commented 1 year ago

@Holofox I made some changes locally, I was able to get the two packages working together.

MissingPluginException is raised because platform side implementation isn't being registered because to an UnsatisfiedLinkError on Java/Kotlin side (you can see it in your logcat). If you check closely, you will notice this has caused none of the plugins to work.

package:ffmpeg_kit_flutter makes some modifications to it's FFmpeg e.g. for allowing usage with Storage Access Framework on Android. When using pickFirst in your build.gradle, the minimal variant of FFmpeg inside package:media_kit gets selected instead of package:ffmpeg_kit_flutter_min_gpl one, which causes that error to be thrown (due to missing export/function).

I will need some time since I'm currently busy with few things. Two solutions I can think of:

Later solution will be bit tedious for me but better to the end users IMO.

alexmercerind commented 1 year ago

You may chat with us on our Discord: https://discord.gg/h7qf2R9n57 ^^

If that's a way of conversation you prefer.

Holofox commented 1 year ago

@alexmercerind, thanks for the explanation! It would be helpful to see any rough work that would even temporarily solve the problem.

birros commented 1 year ago

@Holofox Can you explain me this command, it's the first time I see it:

$ flutter pub get packages
Expected to find project root in packages.

Is your repo multi packages?


But I can run this one:

$ flutter packages pub get
alexmercerind commented 1 year ago

@Holofox,

A temporary solution:

Replace the files in your build/media_kit_libs_android_video directory & comment following lines:

https://github.com/alexmercerind/media_kit/files/11342372/libs.zip

https://github.com/alexmercerind/media_kit/blob/88742704c4c0bb1ee17182a51b689fefbe980b60/media_kit_libs_android_video/android/build.gradle#L86-L110

duh

birros commented 1 year ago

I can't reproduce, the build doesn't fail (macOS 13.3.1)

$ git clone -b 3.7.11 --depth 1 https://github.com/flutter/flutter.git
$ export  PATH="$(pwd)"/flutter/bin:$PATH
$ flutter doctor

$ cd foo
$ flutter packages pub get # <-- replace `flutter pub get packages`
$ flutter packages pub run build_runner build --delete-conflicting-outputs

$ flutter build ios --release -t ./lib/main.dart --no-codesign
Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Building com.example.foo for device (ios-release)...
Running pod install...                                           2 730ms
Running Xcode build...
 └─Compiling, linking and signing...                         8,7s
Xcode build done.                                           17,1s
Built /Users/user/foo/build/ios/iphoneos/Runner.app.

$ ls build/ios/iphoneos/Runner.app/Frameworks
total 0
App.framework
Ass.framework
Avcodec.framework
Avfilter.framework
Avformat.framework
Avutil.framework
Crypto.framework
Flutter.framework
Freetype.framework
Fribidi.framework
Harfbuzz.framework
Mpv.framework
Ssl.framework
Swresample.framework
Swscale.framework
Tls.framework
Uchardet.framework
media_kit_libs_ios_video.framework
media_kit_native_event_loop.framework
media_kit_video.framework

Are you sure that no extra steps happens? Have you tried it locally before the CI?

Holofox commented 1 year ago

@Holofox Can you explain me this command, it's the first time I see it:

Sorry, there is a typo in the command, it is executed as:

flutter pub get

Is your repo multi packages?

Is not

Holofox commented 1 year ago

Are you sure that no extra steps happens?

I did not follow additional steps, I will try to find out more information about the problem.

Have you tried it locally before the CI?

I changed the command and it did not lead to a successful result. Locally the release version builds without any problems.

@sunilguptasg, do you have additional information on the issue?

birros commented 1 year ago

I see two possibilities:

  1. a problem with the .flutter-plugins* files
  2. a problem with a conf file in the ios folder, possibly the Podfile

  1. Try :

    $ rm -f .flutter-plugins* || true
    $ cd ios && pod install
  2. try :

    $ rm -f ios/Podfile* || true
    $ flutter create --platforms=ios .
    $ sed -i '' 's/11.0/13.0/g' ios/Podfile
    $ cd ios && pod install
alexmercerind commented 1 year ago

@Holofox,

[Regarding Android] May you install media_kit_libs_android_video like this & report back if it works?

dependencies:
  ...
  media_kit_libs_android_video: ^1.0.3
alexmercerind commented 1 year ago

[UPDATE]

@Holofox, the updated version should make your project build successfully with package:ffmpeg_kit_flutter:

Also, please update other packages too for improved stability (see in the README).

dependencies:
  ...
  media_kit_libs_android_video: ^1.0.3
Holofox commented 1 year ago

@alexmercerind, ffmpeg_kit_flutter_min_gpl worked, thanks!

Holofox commented 1 year ago

@alexmercerind, I noticed that local videos work, but those that are downloaded from the network do not. Only black screen is shown, video is not loading.

I commented out this part in media_kit_test:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  MediaKit.ensureInitialized();
  runApp(const MyApp(DownloadingScreen()));
  // await prepareSources();
  runApp(const MyApp(PrimaryScreen()));
}

And filled the list with links:

/// List of sample videos available for playback.
final sources = <String>[
  'https://user-images.githubusercontent.com/28951144/229373695-22f88f13-d18f-4288-9bf1-c3e078d83722.mp4',
  'https://user-images.githubusercontent.com/28951144/229373709-603a7a89-2105-4e1b-a5a5-a6c3567c9a59.mp4',
  'https://user-images.githubusercontent.com/28951144/229373716-76da0a4e-225a-44e4-9ee7-3e9006dbc3e3.mp4',
  'https://user-images.githubusercontent.com/28951144/229373718-86ce5e1d-d195-45d5-baa6-ef94041d0b90.mp4',
  'https://user-images.githubusercontent.com/28951144/229373720-14d69157-1a56-4a78-a2f4-d7a134d7c3e9.mp4',
];

And added a dependency:

ffmpeg_kit_flutter_min_gpl: ^5.1.0
alexmercerind commented 1 year ago

@Holofox,

FFmpeg provided by package:ffmpeg_kit_flutter is now shared by package:media_kit. It greatly depends which features they enabled. Try using non *_min_gpl variant which has http:// support.

alexmercerind commented 1 year ago

You can share your experience if other variant of package:ffmpeg_kit_flutter works correctly with http:// URIs.

Holofox commented 1 year ago

You can share your experience if other variant of package:ffmpeg_kit_flutter works correctly with http:// URIs.

@alexmercerind, i changed package to ffmpeg_kit_flutter_https_gpl and it fixed my problem. 🎉

@birros,

  1. a problem with the .flutter-plugins* files

Didn't help fix the issue

2. a problem with a conf file in the ios folder, possibly the Podfile

I ran all the commands, but it didn't help

Holofox commented 1 year ago

@birros, i can confirm that my script successfully finds the pubspec.lock:

current_dir "/Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_video/ios/media_kit_video.podspec"
Check path "/Users/runner/work/1/s/pubspec.lock"
File exist. Set pubspec_lock_path: "/Users/runner/work/1/s/pubspec.lock"

But then a command is launched from the MS App Center:

/usr/local/lib/ruby/gems/3.0.0/bin/pod install --repo-update

And the pwd path changes to: /

2023-05-04T13:42:48.3140850Z ##[section]Starting: Pod install
2023-05-04T13:42:48.3158800Z ==============================================================================
2023-05-04T13:42:48.3158960Z Task         : CocoaPods
2023-05-04T13:42:48.3159050Z Description  : Install CocoaPods dependencies for Swift and Objective-C Cocoa projects
2023-05-04T13:42:48.3159230Z Version      : 0.220.0
2023-05-04T13:42:48.3159310Z Author       : Microsoft Corporation
2023-05-04T13:42:48.3159440Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/cocoapods
2023-05-04T13:42:48.3159570Z ==============================================================================
2023-05-04T13:42:48.6403340Z [command]/usr/local/lib/ruby/gems/3.0.0/bin/pod --version
2023-05-04T13:42:50.7883030Z 1.12.1
2023-05-04T13:42:50.7999290Z [command]/usr/local/lib/ruby/gems/3.0.0/bin/pod install --repo-update
2023-05-04T13:42:52.8624370Z Updating local specs repositories
2023-05-04T13:42:53.0222980Z Analyzing dependencies
2023-05-04T13:42:53.1283550Z make: Nothing to be done for `all'.
2023-05-04T13:42:53.1546170Z make: Nothing to be done for `all'.
2023-05-04T13:42:53.1562700Z current_dir "/Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_video/ios/media_kit_video.podspec"
2023-05-04T13:42:53.1564190Z ERROR: No pubspec.lock was found: ENV["PWD"] = "/"
2023-05-04T13:42:53.1573980Z [!] Failed to load 'media_kit_video' podspec: 
2023-05-04T13:42:53.1574770Z [!] Invalid `media_kit_video.podspec` file: ERROR: No pubspec.lock was found: ENV["PWD"] = "/".
2023-05-04T13:42:53.1574950Z 
2023-05-04T13:42:53.1575230Z  #  from /Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_video/ios/media_kit_video.podspec:27
2023-05-04T13:42:53.1575660Z  #  -------------------------------------------
2023-05-04T13:42:53.1575920Z  #    if pubspec_lock_path == ''
2023-05-04T13:42:53.1576120Z  >      abort(
2023-05-04T13:42:53.1576480Z  #        sprintf('ERROR: No pubspec.lock was found: ENV["PWD"] = "%s"', ENV['PWD'])
2023-05-04T13:42:53.1576870Z  #  -------------------------------------------
2023-05-04T13:42:53.1799300Z ##[error]The process '/usr/local/lib/ruby/gems/3.0.0/bin/pod' failed with exit code 1
2023-05-04T13:42:53.1811520Z ##[error]The 'pod' command failed with error: The process '/usr/local/lib/ruby/gems/3.0.0/bin/pod' failed with exit code 1
2023-05-04T13:42:53.1815310Z ##[section]Finishing: Pod install
birros commented 1 year ago

And the pwd path changes to: "/Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_video/ios/media_kit_video.podspec"

@Holofox Misinterpretation, the current_dir is set to /Users/runner/work/1/s/ios/.symlinks/plugins/media_kit_video/ios/media_kit_video.podspec, but the PWD environment variable is set to /, which is invalid, it should be /Users/runner/work/1/s or /Users/runner/work/1/s/ios.


I see three possibilities:

  1. Skip the CocoaPods task, as the PWD env var seems to be wrong, and since Flutter itself runs a pod install during the build if the iOS build folder is not present or if the pubspec has been changed
  2. Replace the CocoaPods task, and manually run pod install command in the ios folder of the application
  3. Override the PWD env variable with the path to the ios folder when the CocoaPods task is run, however I doubt this solution will work, I have not been able to do this locally when running pod install

In any case, there seems to be a problem with the CocoaPods task in your CI, it might be relevant to open an issue on the appropriate platform.

If none of these solutions work, in the worst case, I can add to the podspec code the fact to use a PWD_FALLBACK env variable if no pubspec was found with PWD, which will need to be set in your pipeline.

Holofox commented 1 year ago

I see three possibilities:

  1. Skip the CocoaPods task, as the PWD env var seems to be wrong, and since Flutter itself runs a pod install during the build if the iOS build folder is not present or if the pubspec has been changed
  2. Replace the CocoaPods task, and manually run pod install command in the ios folder of the application
  3. Override the PWD env variable with the path to the ios folder when the CocoaPods task is run, however I doubt this solution will work, I have not been able to do this locally when running pod install

This can be implemented by migrating to Azure Pipelines, where you can change the configuration of CocoaPods@0. The limitation in this case is that we do not use it and remain within the functionality of the MS App Center.

In any case, there seems to be a problem with the CocoaPods task in your CI, it might be relevant to open an issue on the appropriate platform.

Microsoft rejects any problems related to unofficial custom application build methods. In this case, after executing a custom script, a script for native applications is run, which is useless for Flutter and you can't skip it.

And I also thought about getting around the problem with a symbolic link, but it didn't work out:

ln -s pubspec.lock /pubspec.lock
ln: /pubspec.lock: Read-only file system

If none of these solutions work, in the worst case, I can add to the podspec code the fact to use a PWD_FALLBACK env variable if no pubspec was found with PWD, which will need to be set in your pipeline.

I think this is the only working solution that will help get around the problem. 🥲