Skip to content

Commit

Permalink
feat(*): made a fat lib instead of several libs to avoid conflict bet…
Browse files Browse the repository at this point in the history
…ween native libs.
  • Loading branch information
ThibaultBee committed Oct 21, 2024
1 parent 8d4fc0b commit 66d2ac7
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 40 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.net.URL

plugins {
alias(libs.plugins.android.application).apply(false)
id(libs.plugins.android.application.get().pluginId).apply(false)
id(libs.plugins.android.library.get().pluginId).apply(false)
alias(libs.plugins.kotlin.android).apply(false)
alias(libs.plugins.android.library).apply(false)
alias(libs.plugins.dokka)
}

Expand Down
7 changes: 5 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.kotlin.dsl.`kotlin-dsl`
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -20,4 +19,8 @@ tasks.withType<KotlinCompile> {
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

dependencies {
implementation(libs.android.gradle)
}
10 changes: 10 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "srtdroid-build"
45 changes: 25 additions & 20 deletions buildSrc/src/main/kotlin/Publication.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.the
import org.gradle.plugins.signing.SigningExtension

fun Project.configurePublication() {
apply(plugin = "maven-publish")
apply(plugin = "com.android.library")

the<PublishingExtension>().apply {
publications.create<MavenPublication>("release") {
afterEvaluate {
if (isAndroid) {
from(components.getByName("release"))
} else {
from(components.getByName("java"))
}
}
val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java)

createPom {
name.set(project.name)
description.set(project.description)
configure<PublishingExtension> {
publications {
androidComponents.onVariants(
androidComponents.selector().withBuildType("release")
) { variant ->
register<MavenPublication>(variant.name) {
afterEvaluate {
from(components.getByName(variant.name))
}

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

Expand All @@ -50,8 +56,10 @@ fun Project.configurePublication() {

the<SigningExtension>().apply {
val keyId =
Publication.Signing.keyId ?: throw IllegalStateException("No signing key ID found")
val key = Publication.Signing.key ?: throw IllegalStateException("No signing key found")
Publication.Signing.keyId
?: throw IllegalStateException("No signing key ID found")
val key =
Publication.Signing.key ?: throw IllegalStateException("No signing key found")
val password = Publication.Signing.password
?: throw IllegalStateException("No signing key password found")
useInMemoryPgpKeys(
Expand All @@ -69,11 +77,8 @@ fun Project.configurePublication() {
val Project.isRelease: Boolean
get() = version.toString().endsWith("-SNAPSHOT").not()

val Project.isAndroid: Boolean
get() = project.hasProperty("android")

fun MavenPublication.createPom(
configure: MavenPom.() -> Unit = {}
private fun MavenPublication.createPom(
configure: MavenPom.() -> Unit = {},
): Unit =
pom {
url.set(Publication.Pom.URL)
Expand Down
2 changes: 1 addition & 1 deletion example/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.application)
id(libs.plugins.android.application.get().pluginId)
}

android {
Expand Down
8 changes: 7 additions & 1 deletion srtdroid-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id(libs.plugins.android.library.get().pluginId)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.library)
}

description = "Secure Reliable Transport (SRT) Protocol for Android"

configurePublication()

android {
Expand All @@ -17,6 +18,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

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

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

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

kotlinOptions {
jvmTarget = "1.8"
}

publishing {
singleVariant("release") {
withJavadocJar()
Expand Down
32 changes: 19 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,28 @@ find_program(GIT "git")
set(OPENSSL_VERSION "openssl-3.0.9")
set(SRT_VERSION "1.5.3")

set(ENABLE_SHARED OFF)
set(OPENSSL_FEATURES no-shared)
set(LIBRARY_FORMAT STATIC)
set(LIBRARY_EXTENSION a)

# 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 +40,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 +62,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 crypto ssl z)
7 changes: 6 additions & 1 deletion srtdroid-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id(libs.plugins.android.library.get().pluginId)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.library)
}

description = "Secure Reliable Transport (SRT) Protocol with Kotlin coroutines for Android"

configurePublication()

android {
Expand All @@ -16,6 +17,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

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

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 66d2ac7

Please sign in to comment.