Skip to content

Commit

Permalink
feat(*): add a packed version
Browse files Browse the repository at this point in the history
The packed version is version were all native libraries are put into a single library.
The purpose is to avoid conflict with project that already declared libssl, libcrypto,...
  • Loading branch information
ThibaultBee committed Oct 10, 2024
1 parent 8d4fc0b commit f670326
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 24 deletions.
30 changes: 20 additions & 10 deletions buildSrc/src/main/kotlin/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ fun Project.configurePublication() {
apply(plugin = "com.android.library")

the<PublishingExtension>().apply {
publications.create<MavenPublication>("release") {
afterEvaluate {
if (isAndroid) {
from(components.getByName("release"))
} else {
from(components.getByName("java"))
afterEvaluate {
if (isAndroid) {
components.names.filter { it.lowercase().contains("release") }.forEach {
println("Adding variant $it")
publications.create<MavenPublication>(it) {
from(components.getByName(it))

createPom {
name.set(project.name)
description.set(project.description)
}
}
}
}
} else {
publications.create<MavenPublication>("release") {
from(components.getByName("java"))

createPom {
name.set(project.name)
description.set(project.description)
createPom {
name.set(project.name)
description.set(project.description)
}
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ android {
}
}

flavorDimensions += "packaging"
productFlavors {
create("packed") {
dimension = "packaging"
version = "$version-packed"
}
create("unpacked") {
dimension = "packaging"
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
24 changes: 23 additions & 1 deletion srtdroid-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
}

description = "Secure Reliable Transport (SRT) Protocol for Android"
Expand All @@ -17,6 +17,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
Expand All @@ -26,18 +27,39 @@ android {
)
}
}

externalNativeBuild {
cmake {
path = File("src/main/cpp/CMakeLists.txt")
}
}

flavorDimensions += "packaging"
productFlavors {
create("packed") {
dimension = "packaging"
externalNativeBuild.cmake {
arguments += "-DPACKAGING=PACKED"
}
version = "$version-packed"
}
create("unpacked") {
dimension = "packaging"
externalNativeBuild.cmake {
arguments += "-DPACKAGING=UNPACKED"
}
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

publishing {
singleVariant("release") {
withJavadocJar()
Expand Down
41 changes: 28 additions & 13 deletions srtdroid-core/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,37 @@ find_program(GIT "git")
set(OPENSSL_VERSION "openssl-3.0.9")
set(SRT_VERSION "1.5.3")

set(PACKAGING UNPACKED CACHE STRING "Set packaging type")
set_property(CACHE PACKAGING PROPERTY STRINGS PACKED UNPACKED)
if (${PACKAGING} STREQUAL "PACKED")
set(ENABLE_SHARED OFF)
set(OPENSSL_FEATURES no-shared)
set(LIBRARY_FORMAT STATIC)
set(LIBRARY_EXTENSION a)
set(TARGET_LINK_LIBRARY srt crypto ssl z)
else ()
set(ENABLE_SHARED ON)
set(LIBRARY_FORMAT SHARED)
set(LIBRARY_EXTENSION so)
endif ()

# OpenSSL - needs few executable such as perl and mv in PATH
ExternalProject_Add(openssl_project
GIT_REPOSITORY https://github.com/openssl/openssl.git
GIT_TAG ${OPENSSL_VERSION}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env PATH=${ANDROID_TOOLCHAIN_ROOT}/bin:$ENV{PATH} CC=${CMAKE_C_COMPILER} ANDROID_NDK_ROOT=${ANDROID_NDK} perl <SOURCE_DIR>/Configure android-${ANDROID_ARCH_NAME} --openssldir=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} --libdir="" --prefix=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env PATH=${ANDROID_TOOLCHAIN_ROOT}/bin:$ENV{PATH} CC=${CMAKE_C_COMPILER} ANDROID_NDK_ROOT=${ANDROID_NDK} perl <SOURCE_DIR>/Configure android-${ANDROID_ARCH_NAME} --openssldir=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} --libdir="" --prefix=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} no-tests ${OPENSSL_FEATURES} -D__ANDROID_API__=${ANDROID_PLATFORM_LEVEL}
BUILD_COMMAND ${CMAKE_COMMAND} -E env PATH=${ANDROID_TOOLCHAIN_ROOT}/bin:$ENV{PATH} ANDROID_NDK_ROOT=${ANDROID_NDK} make
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.so
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.${LIBRARY_EXTENSION} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.${LIBRARY_EXTENSION}
BUILD_IN_SOURCE 1
)

add_library(ssl SHARED IMPORTED)
add_library(ssl ${LIBRARY_FORMAT} IMPORTED)
add_dependencies(ssl openssl_project)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.so)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.${LIBRARY_EXTENSION})

add_library(crypto SHARED IMPORTED)
add_library(crypto ${LIBRARY_FORMAT} IMPORTED)
add_dependencies(crypto openssl_project)
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.so)

set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.${LIBRARY_EXTENSION})

# SRT
ExternalProject_Add(srt_project
Expand All @@ -36,8 +49,9 @@ ExternalProject_Add(srt_project
-DENABLE_STDCXX_SYNC=ON
-DENABLE_APPS=OFF
-DOPENSSL_INCLUDE_DIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include
-DOPENSSL_CRYPTO_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.so
-DOPENSSL_SSL_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.so
-DOPENSSL_CRYPTO_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcrypto.${LIBRARY_EXTENSION}
-DOPENSSL_SSL_LIBRARY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libssl.${LIBRARY_EXTENSION}
-DENABLE_SHARED=${ENABLE_SHARED}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_PREFIX_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
-DCMAKE_INSTALL_PREFIX=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
Expand All @@ -57,16 +71,17 @@ ExternalProject_Add(srt_project
-DANDROID_DISABLE_FORMAT_STRING_CHECKS=${ANDROID_DISABLE_FORMAT_STRING_CHECKS}
-DANDROID_CCACHE=${ANDROID_CCACHE}
-DANDROID_SANITIZE=${ANDROID_SANITIZE}
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsrt.so
#-DENABLE_ENCRYPTION=OFF
BUILD_BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsrt.${LIBRARY_EXTENSION}
DEPENDS crypto ssl
BUILD_IN_SOURCE 1
)

add_library(srt SHARED IMPORTED)
add_library(srt ${LIBRARY_FORMAT} IMPORTED)
add_dependencies(srt srt_project)
set_target_properties(srt PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsrt.so)
set_target_properties(srt PROPERTIES IMPORTED_LOCATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsrt.${LIBRARY_EXTENSION})

# Target library
add_library(srtdroid SHARED glue.cpp CallbackContext.cpp)
include_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
target_link_libraries(srtdroid log android srt)
target_link_libraries(srtdroid log android srt ${TARGET_LINK_LIBRARY})
15 changes: 15 additions & 0 deletions srtdroid-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
Expand All @@ -25,13 +26,27 @@ android {
)
}
}

flavorDimensions += "packaging"
productFlavors {
create("packed") {
dimension = "packaging"
version = "$version-packed"
}
create("unpacked") {
dimension = "packaging"
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

publishing {
singleVariant("release") {
withJavadocJar()
Expand Down

0 comments on commit f670326

Please sign in to comment.