DataDog / dd-sdk-reactnative

Datadog SDK for ReactNative
Apache License 2.0
122 stars 42 forks source link

Android build error RN 0.73.3 #606

Closed WesleyFaveri closed 9 months ago

WesleyFaveri commented 9 months ago

Describe what happened

I'm getting build errors after running ./gradlew app:installDevelopmentDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

I couldn't get more info than that....

Additional context

louiszawadzki commented 9 months ago

Hi @WesleyFaveri, thanks for reaching out!

Your error seems very similar to the one that was reported here: https://github.com/DataDog/expo-datadog/issues/23 This should however be fixed for the version 2.0.4 of the SDK, can you double check that you have this version installed locally?

If this is the case, can you run (cd android && ./gradlew :datadog_mobile-react-native:compileDebugKotlin) from the root of your react-native application and share what it returns?

Thanks a lot!

WesleyFaveri commented 9 months ago

That's the version from yarn.lock

"@datadog/mobile-react-native@~2.0.4":
  version "2.0.4"

I'm not using expo maybe that's another issue;

Output from (cd android && ./gradlew :datadog_mobile-react-native:compileDebugKotlin):

Task :datadog_mobile-react-native:compileDebugKotlin FAILED e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:17:1 Class 'DdLogs' is not abstract and does not implement abstract base class member public abstract fun debug(message: String!, context: ReadableMap?, promise: Promise!): Unit defined in com.datadog.reactnative.NativeDdLogsSpec e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:31:5 'debug' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:41:5 'info' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:51:5 'warn' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:61:5 'error' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:75:5 'debugWithError' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:96:5 'infoWithError' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:117:5 'warnWithError' overrides nothing e: file:///{APP_PATH}/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt:138:5 'errorWithError' overrides nothing

FAILURE: Build failed with an exception.

louiszawadzki commented 9 months ago

Hi @WesleyFaveri, thanks for coming back to us quickly!

It seems you are using the RN new architecture, is it correct? Could you share your app/build.gradle and app/gradle.properties files with us so we can try to reproduce the error on our end?

Thanks a lot!

WesleyFaveri commented 9 months ago

Yes, newArchEnabled and hermesEnabled as true

app/build.gradle

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

project.ext.envConfigFiles = [
    development: ".env.development",
    production: ".env.production",
    staging: ".env.staging",
]

project.ext.react = [
    devDisabledInStaging: true,
    bundleInStaging: true,
    bundleInProduction: true,
]

apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

react {}

def enableProguardInReleaseBuilds = true

def jscFlavor = 'org.webkit:android-jsc:+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    flavorDimensions "default"

    namespace "com.app.app"
    defaultConfig {
        applicationId "com.app.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        resValue "string", "build_config_package", "com.app.app"
        resValue "string", "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            storeFile file(System.getenv("ANDROID_UPLOAD_KEYSTORE_PATH") ?: 'debug.keystore')
            storePassword System.getenv("ANDROID_UPLOAD_KEYSTORE_PASSWORD") ?: 'android'
            keyAlias System.getenv("ANDROID_UPLOAD_KEYSTORE_ALIAS") ?: 'androiddebugkey'
            keyPassword System.getenv("ANDROID_UPLOAD_KEYSTORE_PRIVATE_KEY_PASSWORD") ?: 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    productFlavors {
        development {
            applicationIdSuffix 'development'
            resValue "string", "CodePushDeploymentKey", '""'
        }
        staging {
            applicationIdSuffix 'staging'
            resValue "string", "CodePushDeploymentKey", '""'
        }
        production {
            resValue "string", "CodePushDeploymentKey", '""'
        }
    }
}

dependencies {
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:flipper-integration")

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation "androidx.core:core-splashscreen:1.0.0"

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

app/gradle.properties

org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g

android.useAndroidX=true
android.enableJetifier=true

reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

newArchEnabled=true

hermesEnabled=true
fedpre commented 9 months ago

Same issue here and same conditions as OP

ddiachkov commented 9 months ago

I think the specs do not match the implementation.

I've fixed it with this patch and nuking the node_modules to clear cache.

patches/@datadog+mobile-react-native+2.0.2.patch

diff --git a/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt b/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt
index f57b00f..39254a2 100644
--- a/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt
+++ b/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt
@@ -30,14 +30,14 @@ class DdLogsImplementation(
      * @param message The message to send.
      * @param context The additional context to send.
      */
-    fun debug(message: String, context: ReadableMap, promise: Promise) {
+    fun debug(message: String, context: ReadableMap?, promise: Promise) {
         if (!datadog.isInitialized()) {
             promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
             return
         }
         reactNativeLogger.d(
             message = message,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -47,14 +47,14 @@ class DdLogsImplementation(
      * @param message The message to send.
      * @param context The additional context to send.
      */
-    fun info(message: String, context: ReadableMap, promise: Promise) {
+    fun info(message: String, context: ReadableMap?, promise: Promise) {
         if (!datadog.isInitialized()) {
             promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
             return
         }
         reactNativeLogger.i(
             message = message,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -64,14 +64,14 @@ class DdLogsImplementation(
      * @param message The message to send.
      * @param context The additional context to send.
      */
-    fun warn(message: String, context: ReadableMap, promise: Promise) {
+    fun warn(message: String, context: ReadableMap?, promise: Promise) {
         if (!datadog.isInitialized()) {
             promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
             return
         }
         reactNativeLogger.w(
             message = message,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -81,14 +81,14 @@ class DdLogsImplementation(
      * @param message The message to send.
      * @param context The additional context to send.
      */
-    fun error(message: String, context: ReadableMap, promise: Promise) {
+    fun error(message: String, context: ReadableMap?, promise: Promise) {
         if (!datadog.isInitialized()) {
             promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
             return
         }
         reactNativeLogger.e(
             message = message,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -107,7 +107,7 @@ class DdLogsImplementation(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         if (!datadog.isInitialized()) {
@@ -120,7 +120,7 @@ class DdLogsImplementation(
             errorKind = errorKind,
             errorMessage = errorMessage,
             errorStacktrace = stacktrace,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -139,7 +139,7 @@ class DdLogsImplementation(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         if (!datadog.isInitialized()) {
@@ -152,7 +152,7 @@ class DdLogsImplementation(
             errorKind = errorKind,
             errorMessage = errorMessage,
             errorStacktrace = stacktrace,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -171,7 +171,7 @@ class DdLogsImplementation(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         if (!datadog.isInitialized()) {
@@ -184,7 +184,7 @@ class DdLogsImplementation(
             errorKind = errorKind,
             errorMessage = errorMessage,
             errorStacktrace = stacktrace,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
@@ -203,7 +203,7 @@ class DdLogsImplementation(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         if (!datadog.isInitialized()) {
@@ -216,7 +216,7 @@ class DdLogsImplementation(
             errorKind = errorKind,
             errorMessage = errorMessage,
             errorStacktrace = stacktrace,
-            attributes = context.toHashMap() + GlobalState.globalAttributes
+            attributes = (context?.toHashMap() ?: emptyMap()) + GlobalState.globalAttributes
         )
         promise.resolve(null)
     }
diff --git a/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt b/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt
index 3fe0e1d..3e62165 100644
--- a/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt
+++ b/node_modules/@datadog/mobile-react-native/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt
@@ -28,7 +28,7 @@ class DdLogs(
      * @param context The additional context to send.
      */
     @ReactMethod
-    override fun debug(message: String, context: ReadableMap, promise: Promise) {
+    override fun debug(message: String, context: ReadableMap?, promise: Promise) {
         implementation.debug(message, context, promise)
     }

@@ -38,7 +38,7 @@ class DdLogs(
      * @param context The additional context to send.
      */
     @ReactMethod
-    override fun info(message: String, context: ReadableMap, promise: Promise) {
+    override fun info(message: String, context: ReadableMap?, promise: Promise) {
         implementation.info(message, context, promise)
     }

@@ -48,7 +48,7 @@ class DdLogs(
      * @param context The additional context to send.
      */
     @ReactMethod
-    override fun warn(message: String, context: ReadableMap, promise: Promise) {
+    override fun warn(message: String, context: ReadableMap?, promise: Promise) {
         implementation.warn(message, context, promise)
     }

@@ -58,7 +58,7 @@ class DdLogs(
      * @param context The additional context to send.
      */
     @ReactMethod
-    override fun error(message: String, context: ReadableMap, promise: Promise) {
+    override fun error(message: String, context: ReadableMap?, promise: Promise) {
         implementation.error(message, context, promise)
     }

@@ -77,7 +77,7 @@ class DdLogs(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         implementation.debugWithError(message, errorKind, errorMessage, stacktrace, context, promise)
@@ -98,7 +98,7 @@ class DdLogs(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         implementation.infoWithError(message, errorKind, errorMessage, stacktrace, context, promise)
@@ -119,7 +119,7 @@ class DdLogs(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         implementation.warnWithError(message, errorKind, errorMessage, stacktrace, context, promise)
@@ -140,7 +140,7 @@ class DdLogs(
         errorKind: String?,
         errorMessage: String?,
         stacktrace: String?,
-        context: ReadableMap,
+        context: ReadableMap?,
         promise: Promise
     ) {
         implementation.errorWithError(message, errorKind, errorMessage, stacktrace, context, promise)
WesleyFaveri commented 9 months ago

The patch worked for me

louiszawadzki commented 9 months ago

Thanks a lot @WesleyFaveri and @ddiachkov for your inputs on this!

I'm reproducing the issue with the new architecture enabled, I will fix this and let you know once this is released.

louiszawadzki commented 9 months ago

Hi! We've released a fix for this issue in version 2.1.0. I'll close the issue, feel free to reopen it if it is not fixed for you!