Say we have a kotlin class defined as:
package foo
class Bar internal constructor() {
}
When I try to initialize this object from a test method, for example:
package foo
class TestBar {
@Test
fun testingBar() {
Bar()
}
}
I get the following error:
Cannot access '<init>': it is internal in 'Bar'
Both bars and TestBar are in the same AndroidStudio module (android library). Both source paths were defined in gradle:
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}
...
The tests seem to work fine at all, but I can't create any object with an internal constructor.
I use:
ext.kotlin_version = '1.1.3-2'
EDIT
Thanks for the feedback. I decided to make a simple android multi-module application from scratch, and it did a great job.
Then I tried to get rid of the dependencies of my module one by one, and it turns out that the problem is caused by the dagger2 gradle dependency.
dependencies {
...
implementation 'com.google.dagger:dagger:2.8'
kapt 'com.google.dagger:dagger-compiler:2.8'
}
, .
, ?
2 ()
, kapt generatestubs = true.
, . , kapt:
http://kotlinlang.org/docs/reference/kapt.html
kapt {
generateStubs = true
}
apply plugin: kotlin-kapt'
gradle.