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

How to compile the SDK with CS 4.0 in Android in command line? #1136

Open
TedaLIEz opened this issue Apr 21, 2023 · 2 comments
Open

How to compile the SDK with CS 4.0 in Android in command line? #1136

TedaLIEz opened this issue Apr 21, 2023 · 2 comments
Labels
question Further information is requested

Comments

@TedaLIEz
Copy link
Contributor

Please:

  • Describe your scenario.
  • Describe your environment: SDK version, platform, OS version, compiler type, etc.
  • Describe the focus area: transmission controls, offline storage, backend routing controls, reliability, performance, etc.
  • Add any other additional context.

I want to compile this SDK with CS 4.0 support and use it as an AAR in Android. I read through the source code and I found one marco "HAVE_CS4", I tried to compile the SDK based on v3.7.62.1 with flag -DCMAKE_CXX_FLAGS="-DHAVE_CS4=1"

maesdk/build.gradle:

if(!ext.has("build_cpp_client") || ext.build_cpp_client) {
            externalNativeBuild {
                cmake {
                    // Passes optional arguments to CMake.
                    arguments "-DCMAKE_CXX_FLAGS=\"-DHAVE_CS4=1\"", "-DANDROID_STL=c++_shared", "-DBUILD_SHARED_LIBS=1", "-DUSE_ROOM=1", "-DCMAKE_SHARED_LINKER_FLAGS=${project.findProperty("CMAKE_SHARED_LINKER_FLAGS") ?: ''}"
                }
            }
        }

However, this requires us to make changes in your gradle file, and we need to commit this change to repo to track the history. Besides, it makes it hard for us to set up this repo as a git submodule since we have to push the change to remote for submodule.

Can we enable HAVE_CS4 during the build process? For example, we can set this flag in build pipeline like: `./gradlew build -PCXX_FLAG=HAVE_CS4".

@TedaLIEz TedaLIEz added the question Further information is requested label Apr 21, 2023
@lalitb
Copy link
Contributor

lalitb commented Apr 22, 2023

I thought that setting environment variable CXXFLAGS before invoking gradle/gradlew should work, and cmake should pick up the compilation flags automatically from this environment variable. But seems this is not working as you described.

In that case, modifying build.gradle is a fair ask. Something like this should work

if(!ext.has("build_cpp_client") || ext.build_cpp_client) {
            externalNativeBuild {
                cmake {
                    // Passes optional arguments to CMake.
                    arguments "-DCMAKE_CXX_FLAGS=${project.findProperty("CMAKE_CXX_FLAGS") ?: ''}", "-DANDROID_STL=c++_shared", "-DBUILD_SHARED_LIBS=1", "-DUSE_ROOM=1", "-DCMAKE_SHARED_LINKER_FLAGS=${project.findProperty("CMAKE_SHARED_LINKER_FLAGS") ?: ''}"
                }
            }
        }

And then
$ ./gradlew build -PCMAKE_CXX_FLAGS="-DHAVE_CS4=1"

@TedaLIEz - As you are already trying this out, would you like to contribute above changes in this repo. We can help in review and merge.

tagging @anod as he knows these scripts better :)

@anod
Copy link
Member

anod commented Apr 23, 2023

I agree with Lalit that passing parameter to build is more explicit, in CMD, notice there are different 2 properties types:

-D, --system-prop                 Set system property of the JVM (e.g. -Dmyprop=myvalue).
-P, --project-prop                 Set project property for the build script (e.g. -Pmyprop=myvalue).

You can also fallback to env with something like:
-DMAKE_CXX_FLAGS=${project.findProperty("MAKE_CXX_FLAGS") ?: System.getenv("MAKE_CXX_FLAGS")}

For some flags we use explicit parameter in cases where it might be use for cmake configuration (like USE_ROOM), so as an option is to define similar USE_CS4

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

No branches or pull requests

3 participants