Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…make>,  by: <#536>
  • Loading branch information
wysaid committed Dec 15, 2024
1 parent 9d9f601 commit bc98cc3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ tmp
objs/
obj/
build/
library/.cxx/
library/.cxx/
.kotlin/
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ dependencies {
## Build

* Options to know in `local.properties`:
* `usingCMakeCompile=true`: Compile the native library with CMake if set to true. (Default to false, so you can use the prebuilt libs)
* `usingCMakeCompileDebug=true`: Compile the native library in Debug Mode if set to true. (Default to false)
* `disableVideoModule=true`: Disable the video recording feature(Useful for image only scenarios). The whole jni module size will be very small. (Default to false)
* Important options in `local.properties`:
* `usingCMakeCompile=true`: Set to true to compile the native library with CMake. Defaults to false, allowing the use of prebuilt libraries.
* `usingCMakeCompileDebug=true`: Set to true to compile the native library in Debug Mode. Defaults to false.
* `disableVideoModule=true`: Set to true to disable the video recording feature, which is useful for image-only scenarios. This reduces the size of the native library significantly. Defaults to false.
* `enable16kPageSizes=true`: Set to true to enable [16k page sizes](https://developer.android.com/guide/practices/page-sizes#16-kb-impact) for the native library, applicable only in CMake compile mode. Defaults to false.

* Build with `Android Studio` and CMake: (Recommended)
* Put `usingCMakeCompile=true` in your `local.properties`
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.7.2'
classpath 'com.android.tools.build:gradle:8.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -27,14 +27,14 @@ allprojects {
ext {
android = [
compileSdkVersion: 30,
buildToolsVersion: '30.0.3',
minSdkVersion : 16,
buildToolsVersion: '34.0.0',
minSdkVersion : 21,
targetSdkVersion : 25, // higher target version needs more storage permission request.
versionCode : 2,
versionName : "3.0.0",
applicationId : "org.wysaid.cgeDemo",
appcompatX : "1.2.0",
ndkVersion : "23.1.7779620",
ndkVersion : "26.3.11579264",
cmakeVersion : "3.22.1+",
]
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ org.gradle.jvmargs+=-Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
android.injected.testOnly=false
android.defaults.buildfeatures.buildconfig=true
#android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
28 changes: 18 additions & 10 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ def deployArtifacts() {
return gradle.ext != null && gradle.ext.has("deployArtifacts") && gradle.ext.deployArtifacts;
}

def enable16kPageSizes() {
return gradle.ext != null && gradle.ext.has("enable16kPageSizes") && gradle.ext.enable16kPageSizes;
}

android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion

buildFeatures {
buildConfig true
}

if (usingCMakeCompile()) {
ndkVersion rootProject.ext.android.ndkVersion
}
Expand All @@ -35,30 +43,30 @@ android {
if (usingCMakeCompile()) {
externalNativeBuild {
cmake {

def cmakeBuildType = "";
def cppExtraFlags = "";
def cgeVideoModuleDef = "";

if (usingCMakeCompileDebug()) {
cmakeBuildType = "-DCMAKE_BUILD_TYPE=Debug"
cppExtraFlags = "-DDEBUG=1 -D_DEBUG=1 -Od -g"
arguments "-DCMAKE_BUILD_TYPE=Debug"
cppExtraFlags = "-DDEBUG=1 -D_DEBUG=1 -O0 -g"
} else {
cmakeBuildType = "-DCMAKE_BUILD_TYPE=Release"
arguments "-DCMAKE_BUILD_TYPE=Release"
cppExtraFlags = "-Os -DNDEBUG=1 -D_NDEBUG=1"
}

if (disableVideoModule()) {
cgeVideoModuleDef = "-DCGE_USE_VIDEO_MODULE=OFF"
arguments "-DCGE_USE_VIDEO_MODULE=OFF"
} else {
cgeVideoModuleDef = "-DCGE_USE_VIDEO_MODULE=ON"
arguments "-DCGE_USE_VIDEO_MODULE=ON"
}

if (enable16kPageSizes()) {
arguments "-DENABLE_16K_PAGE_SIZES=ON"
}

arguments "-DANDROID_STL=c++_static",
"-DANDROID_ARM_NEON=TRUE",
"-DANDROID_GRADLE=ON",
cmakeBuildType,
cgeVideoModuleDef
"-Wno-deprecated"

cFlags "-ffast-math -fPIE -fPIC -DNO_LOCALE_SUPPORT=1 -DANDROID_NDK=1 -D__STDC_CONSTANT_MACROS=1 ${cppExtraFlags}"
cppFlags "-ffast-math -fPIE -fPIC -DNO_LOCALE_SUPPORT=1 -DANDROID_NDK=1 -D__STDC_CONSTANT_MACROS=1 -frtti -std=c++14 -fno-exceptions -fvisibility-inlines-hidden ${cppExtraFlags}"
Expand Down
26 changes: 8 additions & 18 deletions library/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ else ()
execute_process(COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/cge -maxdepth 3 -type d OUTPUT_VARIABLE CGE_CORE_HEADER_DIR)
endif ()

message("CGE_CORE_HEADER_DIR=${CGE_CORE_HEADER_DIR}")
message(STATUS "CGE_CORE_HEADER_DIR=${CGE_CORE_HEADER_DIR}")
string(REGEX REPLACE "\n" ";" CGE_CORE_HEADER_DIR ${CGE_CORE_HEADER_DIR})

# execute_process(COMMAND bash -c "find \"${CMAKE_CURRENT_SOURCE_DIR}/cge\" -type f -iname '*.cpp' -o -iname '*.c'" OUTPUT_VARIABLE CGE_CORE_SRC)
# string(REGEX REPLACE "\n" ";" CGE_CORE_SRC ${CGE_CORE_SRC})

file(GLOB_RECURSE CGE_CORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/cge/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/cge/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/interface/*.cpp")
Expand All @@ -83,14 +80,6 @@ if (CGE_USE_VIDEO_MODULE)

set(CGE_VIDEO_MODULE "ffmpeg")
add_definitions(-DCGE_USE_FFMPEG=1)
# if (DEFINED ANDROID_ABI)
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/${ANDROID_ABI}/libffmpeg.so
# ${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI}/libffmpeg.so COPYONLY)
# # set_target_properties(ffmpeg PROPERTIES
# # LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI})
# # set_target_properties(ffmpeg PROPERTIES
# # ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI})
# endif ()
endif ()

message("CGE_USE_VIDEO_MODULE=${CGE_USE_VIDEO_MODULE}")
Expand All @@ -110,12 +99,13 @@ file(GLOB_RECURSE CGE_EXT_SRC "${CMAKE_CURRENT_SOURCE_DIR}/custom/*.cpp")

add_library(CGEExt SHARED ${CGE_EXT_SRC})

# if (DEFINED ANDROID_ABI)
# set_target_properties(CGE PROPERTIES
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI})
# set_target_properties(CGEExt PROPERTIES
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI})
# endif ()
target_link_options(CGE PUBLIC -fPIE -fPIC -pie -Wl,-z,relro,-z,now)

if (DEFINED ENABLE_16K_PAGE_SIZES AND ENABLE_16K_PAGE_SIZES)
# 16KB elf: <https://developer.android.com/guide/practices/page-sizes#cmake>
target_link_options(CGE PUBLIC -Wl,-z,max-page-size=16384)
message("ENABLE_16K_PAGE_SIZES=${ENABLE_16K_PAGE_SIZES}")
endif ()

target_link_libraries(CGE
${CGE_VIDEO_MODULE}
Expand Down
7 changes: 6 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if (properties.getProperty('deployArtifacts', null) == null) {
pFile.append('\ndeployArtifacts=false\n')
}

if (properties.getProperty('enable16kPageSizes', null) == null) {
pFile.append('\nenable16kPageSizes=false\n')
}

def homeDir = System.getenv('HOME')
def mavenLocalDir = "maven_local_repo"

Expand All @@ -47,4 +51,5 @@ gradle.ext.usingCMakeCompile = properties.getProperty("usingCMakeCompile", "") =
gradle.ext.usingCMakeCompileDebug = properties.getProperty("usingCMakeCompileDebug", "") == "true"
gradle.ext.disableVideoModule = properties.getProperty("disableVideoModule", "") == "true"
gradle.ext.deployArtifacts = properties.getProperty("deployArtifacts", "") == "true"
gradle.ext.localRepoDir = properties.getProperty("localRepoDir", mavenLocalDir)
gradle.ext.localRepoDir = properties.getProperty("localRepoDir", mavenLocalDir)
gradle.ext.enable16kPageSizes = properties.getProperty("enable16kPageSizes", "") == "true"

0 comments on commit bc98cc3

Please sign in to comment.