diff --git a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePlugin.kt b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePlugin.kt index 6278f153..2280c659 100644 --- a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePlugin.kt +++ b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePlugin.kt @@ -78,26 +78,40 @@ class DdAndroidGradlePlugin @Inject constructor( variant: ApplicationVariant, apiKey: ApiKey ) { - val buildIdGenerationTask = - configureBuildIdGenerationTask(target, androidExtension, variant) - - if (isObfuscationEnabled(variant, datadogExtension)) { - configureVariantForUploadTask( - target, - variant, - buildIdGenerationTask, - apiKey, - datadogExtension - ) - } else { - LOGGER.info("Minifying disabled for variant ${variant.name}, no upload task created") + val isObfuscationEnabled = isObfuscationEnabled(variant, datadogExtension) + val isNativeBuildRequired = variant.externalNativeBuildProviders.isNotEmpty() + + if (isObfuscationEnabled || isNativeBuildRequired) { + val buildIdGenerationTask = + configureBuildIdGenerationTask(target, androidExtension, variant) + + if (isObfuscationEnabled) { + configureVariantForUploadTask( + target, + variant, + buildIdGenerationTask, + apiKey, + datadogExtension + ) + } else { + LOGGER.info("Minifying disabled for variant ${variant.name}, no mapping file upload task created") + } + + if (isNativeBuildRequired) { + configureNdkSymbolUploadTask( + target, + datadogExtension, + variant, + buildIdGenerationTask, + apiKey + ) + } else { + LOGGER.info( + "No native build tasks found for variant ${variant.name}," + + " no NDK symbol file upload task created." + ) + } } - configureNdkSymbolUploadTask( - target, - datadogExtension, - variant, - buildIdGenerationTask - ) configureVariantForSdkCheck(target, variant, datadogExtension) } @@ -118,9 +132,9 @@ class DdAndroidGradlePlugin @Inject constructor( target: Project, extension: DdExtension, variant: ApplicationVariant, - buildIdTask: TaskProvider - ): TaskProvider? { - val apiKey = resolveApiKey(target) + buildIdTask: TaskProvider, + apiKey: ApiKey + ): TaskProvider { val extensionConfiguration = resolveExtensionConfiguration(extension, variant) val uploadTask = DdNdkSymbolFileUploadTask.register( diff --git a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdNdkSymbolFileUploadTask.kt b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdNdkSymbolFileUploadTask.kt index 5ee057c0..eeb1b8ef 100644 --- a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdNdkSymbolFileUploadTask.kt +++ b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdNdkSymbolFileUploadTask.kt @@ -7,7 +7,6 @@ import com.datadog.gradle.plugin.internal.Uploader import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty -import org.gradle.api.logging.Logging import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory @@ -89,8 +88,6 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor( SupportedArchitectureMapping("x86_64", "x64") ) - internal val LOGGER = Logging.getLogger("DdSymbolFileUploadTask") - private fun getSearchDirs( buildTask: TaskProvider, providerFactory: ProviderFactory @@ -122,13 +119,7 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor( apiKey: ApiKey, extensionConfiguration: DdExtensionConfiguration, repositoryDetector: RepositoryDetector - ): TaskProvider? { - val nativeBuildProviders = variant.externalNativeBuildProviders - if (nativeBuildProviders.isEmpty()) { - LOGGER.info("No native build tasks found for variant ${variant.name}, skipping NDK symbol file upload.") - return null - } - + ): TaskProvider { return project.tasks.register( TASK_NAME + variant.name.capitalize(), DdNdkSymbolFileUploadTask::class.java, @@ -145,6 +136,7 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor( } task.sourceSetRoots = roots + val nativeBuildProviders = variant.externalNativeBuildProviders nativeBuildProviders.forEach { buildTask -> val searchFiles = getSearchDirs(buildTask, providerFactory) diff --git a/dd-sdk-android-gradle-plugin/src/test/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePluginTest.kt b/dd-sdk-android-gradle-plugin/src/test/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePluginTest.kt index 03d77b04..0c05e8b0 100644 --- a/dd-sdk-android-gradle-plugin/src/test/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePluginTest.kt +++ b/dd-sdk-android-gradle-plugin/src/test/kotlin/com/datadog/gradle/plugin/DdAndroidGradlePluginTest.kt @@ -435,7 +435,7 @@ internal class DdAndroidGradlePluginTest { } @Test - fun `M create buildId task W configureTasksForVariant() { no deobfuscation }`( + fun `M not create buildId task W configureTasksForVariant() { no deobfuscation, no native build providers }`( @StringForgery(case = Case.LOWER) flavorName: String, @StringForgery(case = Case.LOWER) buildTypeName: String, @StringForgery versionName: String, @@ -465,7 +465,7 @@ internal class DdAndroidGradlePluginTest { // Then val allTasks = fakeProject.tasks.map { it.name } - assertThat(allTasks).contains("generateBuildId${variantName.replaceFirstChar { capitalizeChar(it) }}") + assertThat(allTasks).doesNotContain("generateBuildId${variantName.replaceFirstChar { capitalizeChar(it) }}") } @Test