DataDog / dd-sdk-android-gradle-plugin

The Datadog Gradle Plugin for Android
Apache License 2.0
14 stars 9 forks source link

./gradlew uploadMappingRelease crashing #252

Closed tomdiz-epicorebiosystems closed 6 months ago

tomdiz-epicorebiosystems commented 7 months ago

Do a successful release build (mapping.txt file in default release folder). Export DD_API_KEY with my API key and then run ./gradlew uploadMappingRelease from the Terminal window. Get this crash:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.datadog.gradle.plugin.internal.OkHttpUploader
at com.datadog.gradle.plugin.DdFileUploadTask.(DdFileUploadTask.kt:35)
at com.datadog.gradle.plugin.DdMappingFileUploadTask.(DdMappingFileUploadTask.kt:23)
at com.datadog.gradle.plugin.DdMappingFileUploadTask_Decorated.(Unknown Source)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:2097)
at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:524)
at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:50)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:88)
... 173 more
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoSuchFieldError: Class okhttp3.MediaType does not have member field 'okhttp3.MediaType$Companion Companion' [in thread "Daemon worker Thread 29"]
at com.datadog.gradle.plugin.internal.OkHttpUploader.(OkHttpUploader.kt:276)
... 182 more

My gradle file contains:

plugins {
  id("com.datadoghq.dd-sdk-android-gradle-plugin") version "1.13.1"
  id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10" // NOTE: This needs to match kotlin version
}

At the bottom of my gradle file is:

datadog {
  site = "US5"
}
0xnm commented 7 months ago

Hello @tomdiz-epicorebiosystems!

Most probably you have old OkHttp 3 version pinned by you or resolved by Gradle for the build environment classpath. The missing OkHttp3.Companion class referenced in your error was introduced here and exists only since OkHttp 4.x release.

You can check which version of OkHttp is used in your build environment by running ./gradlew :<module>:buildEnvironment task.

Our plugin expects to have OkHttp 4.x or above in the classpath.

tomdiz-epicorebiosystems commented 6 months ago

Hi,

I ran the above command for my app (terminal window) and see com.squareup.okhttp3:okhttp:4.12.0 included. I also add the 4.12.0 jar to my classpath and got duplicate issues..

./gradlew :app:buildEnvironment

Configure project :app fatal: No names found, cannot describe anything. fatal: No names found, cannot describe anything.

Configure project :lib_service fatal: No names found, cannot describe anything.

Configure project :lib_ui fatal: No names found, cannot describe anything.

Configure project :profile_uart fatal: No names found, cannot describe anything.

Task :app:buildEnvironment


Project ':app'

classpath +--- com.datadoghq.dd-sdk-android-gradle-plugin:com.datadoghq.dd-sdk-android-gradle-plugin.gradle.plugin:1.13.1 | --- com.datadoghq:dd-sdk-android-gradle-plugin:1.13.1 | +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 1.8.10 | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.10 | | --- org.jetbrains:annotations:13.0 | +--- com.squareup.okhttp3:okhttp:4.12.0 | | +--- com.squareup.okio:okio:3.6.0 | | | --- com.squareup.okio:okio-jvm:3.6.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10 -> 1.8.10 | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 () | | | | --- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10 | | | | --- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 () | | | --- org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10 -> 1.8.10 | | --- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.8.10 () | --- org.json:json:20180813 +--- org.jetbrains.kotlin.plugin.serialization:org.jetbrains.kotlin.plugin.serialization.gradle.plugin:1.9.10 | --- org.jetbrains.kotlin:kotlin-serialization:1.9.10 | +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.10 | | +--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:1.9.10 | | | +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.10 (c) | | | +--- org.jetbrains.kotlin:kotlin-serialization:1.9.10 (c) | | | +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:1.9.10 (c) | | | +--- org.jetbrains.kotlin:kotlin-native-utils:1.9.10 (c) | | | --- org.jetbrains.kotlin:kotlin-tooling-core:1.9.10 (c) | | +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:1.9.10 | | +--- org.jetbrains.kotlin:kotlin-native-utils:1.9.10 | | | +--- org.jetbrains.kotlin:kotlin-util-io:1.9.10 | | | --- org.jetbrains.kotlin:kotlin-util-klib:1.9.10 | | | --- org.jetbrains.kotlin:kotlin-util-io:1.9.10 | | +--- org.jetbrains.kotlin:kotlin-project-model:1.9.10 | | | --- org.jetbrains.kotlin:kotlin-tooling-core:1.9.10 | | --- org.jetbrains.kotlin:kotlin-tooling-core:1.9.10 | --- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:1.9.10 () +--- org.jetbrains.kotlin:kotlin-stdlib:{strictly 1.8.10} -> 1.8.10 (c) +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{strictly 1.8.10} -> 1.8.10 (c) +--- org.jetbrains.kotlin:kotlin-stdlib-common:{strictly 1.8.10} -> 1.8.10 (c) +--- org.jetbrains:annotations:{strictly 13.0} -> 13.0 (c) --- org.jetbrains.kotlin:kotlin-stdlib-jdk7:{strictly 1.8.10} -> 1.8.10 (c)

(c) - A dependency constraint, not a dependency. The dependency affected by the constraint occurs elsewhere in the tree. (*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 814ms 1 actionable task: 1 executed

0xnm commented 6 months ago

@tomdiz-epicorebiosystems By looking on the buildEnvironment output I can see that the necessary OkHttp version exists in your build classpath, there is no need to add a jar manually. Did you try to make a clean build by removing all build cache files? What if you update Kotlin version used in your project to 1.9, does this issue still occur?

tomdiz-epicorebiosystems commented 6 months ago

Hi,

I removed all cache files and verified I'm using Kotlin 1.9. The issue still occurred. I was using the Nordic Semiconductor Android-BLE-Library (with gradle lib version 1.9.13) in my project. I finally figured out they are pulling in okHttp 3.x and that was causing the failure of uploadMappingRelease with crash exception. I upgraded Noridic libs by removing there gradle lib and adding fixed lib versions of there Libraries. It is working fine now. Thx for your help.

0xnm commented 6 months ago

@tomdiz-epicorebiosystems glad to hear the issue is resolved now!