Skip to content

feat: allow to specify NO_OPUS_OGG_LIBS exclusion in Android build files #198

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

Open
1 task
ekuleshov opened this issue Mar 8, 2025 · 8 comments
Open
1 task

Comments

@ekuleshov
Copy link

Description

The current instructions require to specify ENV variable NO_OPUS_OGG_LIBS to exclude Opus and Ogg libraries. It would be really handy to be able to have it somehow defined in the Android build files.

Requirements

  • Allow to specify exclusion for Opus and Ogg libraries in the Android target build files (i.e. Gradle scripts)

Additional Context

As an alternative maybe you could publish a separate artifact to pub.dev like flutter_soloud_no_ogg or a version like 3.0.3-no-ogg. The ffmpeg_kit_flutter plugin used this approach to distribute various platform binaries.

@alnitak
Copy link
Owner

alnitak commented Mar 8, 2025

Hi @ekuleshov,

I didn't try, but I think you can add something like this in the app/build.gradle:

android {
    ...
    externalNativeBuild {
        cmake {
            environment "NO_OPUS_OGG_LIBS", "1"
        }
    }
    ...
}

updated ^^

or maybe also add this line in the settings.gradle:

NO_OPUS_OGG_LIBS=1

I can't try now, but please let me know if one of those works, so I can update the doc!

@ekuleshov
Copy link
Author

@alnitak it needs to be android / defaultConfig / externalNativeBuild / cmake...

But unfortunately the cmake Gradle task doesn't have environment option.

https://developer.android.com/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeBuildOptions

There are arguments, cFlags and cppFalgs. E.g. example from the docs below.

I tried to add arguments "-DNO_OPUS_OGG_LIBS=1" but the ogg libs are still bundled when running flutter build appbundle command, because flutter_soloud/android/CMakeLists.txt is always looking for the ENV variable.

Using argument like -DNO_OPUS_OGG_LIBS also fail with a cmake command line syntax error, because it expects name=value.

So, it is likely necessary to change the Android's CMakeLists.txt to also look at the arguments like below. Then the following Gradle change seem to work:

android {
   ...
    defaultConfig {
        ...
        externalNativeBuild {
            cmake {
                arguments "-DNO_OPUS_OGG_LIBS=1"
            }
        }
    }
   ...
Image

@alnitak
Copy link
Owner

alnitak commented Mar 8, 2025

When you added AND NOT DEFINED NO_OPUS_OGG_LIBS the plugin rebuild has been triggered by the change made on CMakeLists. If you then try to remove the lines from build.gradle and try to run again, the change has no effects and the plugin is not rebuilt (the libs are not linked).

I am trying to figure out the gradle tasks to see if there is something that can help.

@ekuleshov
Copy link
Author

@alnitak my thought was to pass a cmake command line argument that would be used in that condition.

I wasn't been able to find a way to set ENV variable for that cmake build. Also tried this with no success:

tasks.withType(Exec) {
    environment "NO_OPUS_OGG_LIBS", "1"
}

@alnitak
Copy link
Owner

alnitak commented Mar 8, 2025

yes, I tried that also and some other things but still nothing. I am still trying, but just out of curiosity, why not use the IDE trick to set the variable or use the command line to run the app (or a GitHub action for building):

export NO_OPUS_OGG_LIBS="1" && flutter run

This thing we are doing of course ca be handy, but it's driving me crazy 😃

@ekuleshov
Copy link
Author

...why not use the IDE trick to set the variable...

Just trying to make build self-contained and having general command flutter build appbundle do the right thing without additional parameters that has to be remembered or set somewhere.

I'm still somewhat puzzled why condition like (NOT DEFINED ENV{NO_OPUS_OGG_LIBS} AND NOT DEFINED NO_OPUS_OGG_LIBS) won't work.

@alnitak
Copy link
Owner

alnitak commented Mar 10, 2025

I'm still somewhat puzzled why condition like (NOT DEFINED ENV{NO_OPUS_OGG_LIBS} AND NOT DEFINED NO_OPUS_OGG_LIBS) won't work.

On Android gradle decides, with the building tasks, what needs to be built. If you change some native sources or the CMakeLists, the native build is for sure triggered, but if you change an environment variable, nothing is changed for gradle and nothing is rebuilt.

To trigger the rebuild when an environment variable is changed, I have added this task which triggers the externalNativeBuild with a cmake argument. If this argument changes, the rebuild is performed.

This is what I understood looking around, but maybe I am wrong. Anyway it works :)

I tried this approach in the app gradle without success, I think because the app does not need to build native code.

@ekuleshov
Copy link
Author

@alnitak I don't think it is a concern. It rebuilds when Gradle scripts or CMakeLists are edited. I also used flutter clean to get a fresh full rebuild. It probably isn't something that will be changed back and forth.

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

No branches or pull requests

2 participants