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

[Android] FFMPEG as dynamic feature no Log output #593

Closed
DaXmYsT opened this issue Oct 10, 2022 · 8 comments
Closed

[Android] FFMPEG as dynamic feature no Log output #593

DaXmYsT opened this issue Oct 10, 2022 · 8 comments
Assignees
Labels
android Affect Android platform enhancement New feature or request fixed-in-v6.0 library Affects the library v5.1 Affects v5.1 release

Comments

@DaXmYsT
Copy link

DaXmYsT commented Oct 10, 2022

First, thanks to @tanersener for your great work!

Description
I'm not sure if it is a bug or If I'm missing something: I was able to outsource FFMPEG to a dynamic feature (to eliminate the large app size problem). The logic is working and FFMPEG is working, but I'm not getting any log outout from FFMPEG. I updated an old sample project to demonstrate the issue (see attached)

Expected behavior
I will see the log outputs from FFMPEG even if I use a dynamic feature

Current behavior
FFMPEG is working, but no log outputs are created

To Reproduce
To show a working example: Just install the demo project directly to a smartphone. In that case, the dynamic feature will be installed automatically as a normal feature and FFMPEG will create a normal output you can see inside logcat.

To test the problem, click in Android Studio BUILD -->Build Bundles / Apks --> Build bundle(s)
Now, copy the created app-debug.aab file to an empty folder.

Next, download bundletool for local testing the dynamic feature. You can find the latest version here: https://github.com/google/bundletool/releases copy bundletool to the same directory you copied the .aab file.

Now, do the following commands with connected smartphone and uninstalled demo app:

java -jar bundletool-all-1.11.2.jar build-apks --bundle=app-debug.aab --output=dynamicfeature.apks --local-testing

To install the generated .apks file, do the following:

java -jar bundletool-all-1.11.2.jar install-apks --apks=dynamicfeature.apks

Now test the app. You will see, that the app will be downloaded successful, and you can start it successful. But you won't see any log output. You can also try to read the logs from the session, it will be always empty.

Environment

  • Platform: Android/
  • Architecture: arm64-v8a,
  • Version: v5.1.LTS
  • Source branch: main, development
  • Android Studio version: Android Studio Dolphin | 2021.3.1
  • Android NDK version: ndkVersion '22.1.7171670'

Other
If you open the MainActivity, you will see the following code line 126 ff.:

                        SplitCompat.installActivity(this);
                        SplitInstallHelper.loadLibrary(this, "c++_shared");
                        SplitInstallHelper.loadLibrary(this, "avutil");
                        SplitInstallHelper.loadLibrary(this, "swresample");
                        SplitInstallHelper.loadLibrary(this, "avcodec");
                        SplitInstallHelper.loadLibrary(this, "avformat");
                        SplitInstallHelper.loadLibrary(this, "swscale");
                        SplitInstallHelper.loadLibrary(this, "avfilter");
                        SplitInstallHelper.loadLibrary(this, "avdevice");
                        SplitInstallHelper.loadLibrary(this, "ffmpegkit");
                        SplitInstallHelper.loadLibrary(this, "ffmpegkit_abidetect");

Maybe I forgot one library?

Attachment:
DynamicDelivery.zip

@tanersener
Copy link
Collaborator

Thanks for creating this issue.

I haven't used Android's dynamic feature before. Hope you can give me some time to look at how it works with your app.

@tanersener tanersener added needs-analysis We don't know that this is. It must be investigated further android Affect Android platform v5.1 Affects v5.1 release library Affects the library labels Oct 12, 2022
@DaXmYsT
Copy link
Author

DaXmYsT commented Oct 13, 2022

Sure, take your time. :)

It is very useful in many cases to reduce the App size. My work-around at the moment is to check if a file was created or not (for example, create an image thumbnail from a video). But with logs, it would be better to track issues with an input file.

@tanersener
Copy link
Collaborator

I tried to test the app using your instructions. But install-apks command doesn't do anything for me. Do you see anything wrong in the logs?

> java -jar bundletool-all-1.11.2.jar install-apks --apks=dynamicfeature.apks
The APKs have been extracted in the directory: /var/folders/mb/vz1pz9q53t333bzj3vxmlgp40000gn/T/16170500817657349095
The APKs have been extracted in the directory: /var/folders/mb/vz1pz9q53t333bzj3vxmlgp40000gn/T/16170500817657349095
ADB << rm -rf '/sdcard/Android/data/com.example.dynamicdemo/files/local_testing'
ADB >> OK
ADB << mkdir -p '/sdcard/Android/data/com.example.dynamicdemo/files/local_testing' && rmdir '/sdcard/Android/data/com.example.dynamicdemo/files/local_testing' && mkdir -p '/sdcard/Android/data/com.example.dynamicdemo/files/local_testing'
ADB >> OK
Pushed "/sdcard/Android/data/com.example.dynamicdemo/files/local_testing/base-master.apk"
Pushed "/sdcard/Android/data/com.example.dynamicdemo/files/local_testing/encoder-master.apk"
Pushed "/sdcard/Android/data/com.example.dynamicdemo/files/local_testing/encoder-arm64_v8a.apk"
ADB << chmod 775 '/sdcard/Android/data/com.example.dynamicdemo/files/local_testing'
ADB >> OK
ADB << run-as 'com.example.dynamicdemo' rm -rf '/data/data/com.example.dynamicdemo/files/splitcompat'
ADB >> OK

Logcat logs

@DaXmYsT
Copy link
Author

DaXmYsT commented Oct 14, 2022

No, it looks right. The app should have been installed on your phone. You are not getting an additional notification. You also have to start it manually, it will not autostart.

Edit:

Please make sure to use the debug flavor for the app and the encoder module when you create the appbundle.

After you entered

> java -jar bundletool-all-1.11.2.jar install-apks --apks=dynamicfeature.apks

Please try the following:
adb shell am start -n com.example.dynamicdemo/com.example.dynamicdemo.MainActivity

@tanersener
Copy link
Collaborator

Thanks. I managed to start the application with that command.

So, when I click the download button I get the following permission error. Is this something you've seen before. I tried on multiple devices, both received this exception.

com.example.dynamicdemo              D  app_time_stats: avg=703.73ms min=1.91ms max=6975.35ms count=10
com.example.dynamicdemo              W  type=1400 audit(0.0:410): avc: denied { getattr } for path="/storage/emulated/0/Android/data/com.example.dynamicdemo/files/local_testing/encoder-master_2.apk" dev="dm-4" ino=30757 scontext=u:r:untrusted_app:s0:c151,c256,c512,c768 tcontext=u:object_r:storage_file:s0 tclass=file permissive=0 app=com.example.dynamicdemo
com.example.dynamicdemo              W  type=1400 audit(0.0:411): avc: denied { getattr } for path="/storage/emulated/0/Android/data/com.example.dynamicdemo/files/local_testing/encoder-arm64_v8a_2.apk" dev="dm-4" ino=30758 scontext=u:r:untrusted_app:s0:c151,c256,c512,c768 tcontext=u:object_r:storage_file:s0 tclass=file permissive=0 app=com.example.dynamicdemo
com.example.dynamicdemo              I  availableSplits [, encoder, encoder.config.arm64_v8a] want [encoder]
com.example.dynamicdemo              D  app_time_stats: avg=18.49ms min=2.24ms max=238.42ms count=52
com.example.dynamicdemo              D  app_time_stats: avg=1015.73ms min=1015.73ms max=1015.73ms count=1
com.example.dynamicdemo              I  Copying splits.
com.example.dynamicdemo              W  type=1400 audit(0.0:412): avc: denied { read } for name="encoder-master_2.apk" dev="dm-4" ino=30757 scontext=u:r:untrusted_app:s0:c151,c256,c512,c768 tcontext=u:object_r:storage_file:s0 tclass=file permissive=0 app=com.example.dynamicdemo
com.example.dynamicdemo              E  Error copying splits.
                                        java.io.FileNotFoundException: open failed: EACCES (Permission denied)
                                     	    at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:342)
                                     	    at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:229)
                                     	    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1837)
                                 	    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1758)
                                 	    at com.google.android.play.core.internal.at.e(Unknown Source:76)
                                 	    at com.google.android.play.core.internal.at.d(Unknown Source:0)
                                 	    at com.google.android.play.core.internal.as.run(Unknown Source:28)
                                 	    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                 	    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                 	    at java.lang.Thread.run(Thread.java:920)
com.example.dynamicdemo              D  app_time_stats: avg=1006.43ms min=1006.43ms max=1006.43ms count=1

@DaXmYsT
Copy link
Author

DaXmYsT commented Oct 17, 2022

It looks like a permission error, you can see "untrusted app" in the log. You maybe need to enable install apps from untrusted sources. I don't know which phone you are using, but you should be able to activate it within the android settings.

You can also try to install the App from android studio directly first and check if you have a valid logcat output. If this is also not working, you have to activate install app from untrusted sources.

You can also try to run the code on an emulator. I haven't tested that, but this should also work.

@tanersener
Copy link
Collaborator

Yeah, it was an application permission error. The app needed file access permissions to be able to read split files. Thanks for your suggestions.

So, I managed to reproduce this case. The following logs explain what happens there.

ffmpeg-kit              com.example.dynamicdemo              I  Loading ffmpeg-kit.
ffmpeg-kit              com.example.dynamicdemo              I  Loaded ffmpeg-kit-full-gpl-arm64-v8a-4.5.1-lts-20220101.
ffmpeg-kit              com.example.dynamicdemo              D  Async callback block started.
ffmpeg-kit              com.example.dynamicdemo              D  Async callback block stopped.

We have a log redirection feature that is responsible of capturing ffmpeg console output and invoking callbacks. It is a separate thread and started by enableRedirection() method when ffmpeg-kit library is loaded.
Logs show that that thread stops when the libraries are loaded as dynamic feature. That's why you don't see any logs for your sessions.

Why that happens? Because the initialisation sequence for the Android library is developed assuming that the library is loaded using the Java API, not natively.
I just pushed a commit on the development branch to support loading the library natively as well. That one fixes this issue.

If you don't want to build the development branch, you can also call the FFmpegKitConfig.enableRedirection() method before starting a new session. It is an idempotent method. It will enable redirection and logs will be captured by the callback thread.

@tanersener tanersener self-assigned this Oct 17, 2022
@tanersener tanersener added enhancement New feature or request fixed-on-development Fixed on the development branch. Not released yet. and removed needs-analysis We don't know that this is. It must be investigated further labels Oct 17, 2022
@DaXmYsT
Copy link
Author

DaXmYsT commented Oct 18, 2022

Thank you for your hint. Yes, it is working perfectly now. :)

@DaXmYsT DaXmYsT closed this as completed Oct 18, 2022
@tanersener tanersener added fixed-in-v6.0 and removed fixed-on-development Fixed on the development branch. Not released yet. labels Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Affect Android platform enhancement New feature or request fixed-in-v6.0 library Affects the library v5.1 Affects v5.1 release
Projects
No open projects
Development

No branches or pull requests

2 participants