How to compile the SDK with CS 4.0 in Android in command line?
TedaLIEz opened this issue · 2 comments
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".
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 :)
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