Cannot access internal constructor from unit test when adding Dagger 2 as dependency


#1

Let say we have a kotlin class defined as:

package foo
class Bar internal constructor() {
//...
}

When I try to init that object from a test method like:

package foo
class BarTest {
    @Test
    fun testingBar() {
        Bar()  //<----- error
    }
}

I get a following error:
Cannot access '<init>': it is internal in 'Bar'

Both Bar and BarTest are in the same AndroidStudio module (android library) Both paths to sources were defined in a gradle:

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
    test.java.srcDirs += 'src/test/kotlin'
}

I’m using
ext.kotlin_version = '1.1.3-2'


I’ve tried to find the cause and it turns out that when I remove dagger 2 dependency the problem goes away.

//dagger 2
implementation 'com.google.dagger:dagger:2.8'
kapt 'com.google.dagger:dagger-compiler:2.8' //<---- this is causing errors

In this sample project dagger isn’t used anywhere. Just adding dependency to gradle causes accessing classes with internal constructor impossible.