diff --git a/build.gradle.kts b/build.gradle.kts index 79ac7cb2..690ffcf6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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) } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6f2cab93..34a4a944 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,4 +1,3 @@ -import org.gradle.kotlin.dsl.`kotlin-dsl` import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -20,4 +19,8 @@ tasks.withType { java { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file +} + +dependencies { + implementation(libs.android.gradle) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 00000000..eefe703d --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,10 @@ +dependencyResolutionManagement { + @Suppress("UnstableApiUsage") + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "srtdroid-build" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Publication.kt b/buildSrc/src/main/kotlin/Publication.kt index 017c4783..85c98022 100644 --- a/buildSrc/src/main/kotlin/Publication.kt +++ b/buildSrc/src/main/kotlin/Publication.kt @@ -1,9 +1,11 @@ +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 @@ -11,19 +13,23 @@ fun Project.configurePublication() { apply(plugin = "maven-publish") apply(plugin = "com.android.library") - the().apply { - publications.create("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 { + publications { + androidComponents.onVariants( + androidComponents.selector().withBuildType("release") + ) { variant -> + register(variant.name) { + afterEvaluate { + from(components.getByName(variant.name)) + } + + createPom { + name.set(project.name) + description.set(project.description) + } + } } } @@ -50,8 +56,10 @@ fun Project.configurePublication() { the().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( @@ -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) diff --git a/example/build.gradle.kts b/example/build.gradle.kts index 185e901f..05b0c92b 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,6 +1,6 @@ plugins { alias(libs.plugins.kotlin.android) - alias(libs.plugins.android.application) + id(libs.plugins.android.application.get().pluginId) } android { diff --git a/srtdroid-core/build.gradle.kts b/srtdroid-core/build.gradle.kts index a7d5e3c8..5885fada 100644 --- a/srtdroid-core/build.gradle.kts +++ b/srtdroid-core/build.gradle.kts @@ -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 { @@ -17,6 +18,7 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } + buildTypes { release { isMinifyEnabled = false @@ -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() diff --git a/srtdroid-core/src/main/cpp/CMakeLists.txt b/srtdroid-core/src/main/cpp/CMakeLists.txt index fb49a9ad..cad447b4 100644 --- a/srtdroid-core/src/main/cpp/CMakeLists.txt +++ b/srtdroid-core/src/main/cpp/CMakeLists.txt @@ -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 /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 /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 @@ -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} @@ -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 ${TARGET_LINK_LIBRARY}) diff --git a/srtdroid-ktx/build.gradle.kts b/srtdroid-ktx/build.gradle.kts index 466a54f0..fc36811c 100644 --- a/srtdroid-ktx/build.gradle.kts +++ b/srtdroid-ktx/build.gradle.kts @@ -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 { @@ -16,6 +17,7 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") } + buildTypes { release { isMinifyEnabled = false @@ -25,13 +27,16 @@ android { ) } } + compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } + kotlinOptions { jvmTarget = "1.8" } + publishing { singleVariant("release") { withJavadocJar()