https://kotlinlang.org logo
#android
Title
# android
m

masteramyx

01/28/2023, 4:04 AM
I receive an error warning in android studio when using a kotlin constructor in a java class.
Copy code
Timber.plant(new DatadogTree(logger));
"Cannot resolve method 'plant(com.datadog.android.timber.DatadogTree)'" Compiles fine I wonder if this is a bug with AS?
😶 2
1
c

Chrimaeon

01/28/2023, 9:35 AM
Did you get an error or a warning? What is the baseclass of
DatadogTree
?
m

masteramyx

01/28/2023, 3:57 PM
This is not just a Java question. This is clearly around java-kotlin interop Well its a red squiggly line which indicates error. I'm wondering if this is IDE error or maybe DatadogTree is missing some annotation that expose the constructor to my java class. DatadogTree.kt
Copy code
/*
 * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
 * This product includes software developed at Datadog (<https://www.datadoghq.com/>).
 * Copyright 2016-Present Datadog, Inc.
 */

package com.datadog.android.timber

import com.datadog.android.log.Logger
import timber.log.Timber

/**
 * An implementation of a [Timber.Tree], forwarding all logs to the provided [Logger].
 *
 * @param logger the logger to use with Timber.
 */
class DatadogTree(
    private val logger: Logger
) :
    Timber.Tree() {

    /**
     * Creates a [Timber.Tree] with a default [Logger] having a minimum log priority
     * for Datadog logs set to specified value.
     *
     * See [Logger.Builder.setDatadogLogsMinPriority] for details.
     *
     * @param minLogPriority Minimum log priority to be sent to the Datadog servers.
     */
    constructor(minLogPriority: Int) :
        this(
            Logger.Builder()
                .setDatadogLogsMinPriority(minLogPriority)
                .build()
        )

    init {
        logger.addTag("android:timber")
    }

    override fun log(
        priority: Int,
        tag: String?,
        message: String,
        t: Throwable?
    ) {
        logger.log(priority, message, t)
    }
}
c

Chrimaeon

01/28/2023, 7:58 PM
Yeah, looks like an IDE issue. Compiling is just fine but has the same issue with i.e.
DebugTree
. seems AS cannot infer the base class even with this:
Copy code
final Timber.Tree tree = new Timber.DebugTree();
thank you color 1
59 Views