1

I'm here to report my problem for what it seems I can't find any solution on the internet, so I decided to write here, I've been trying for days to solve this and I still don't understand where the reason for the error is. The error basically is, I can't import the class that is generated in navigations, Directions, when I write the whole path or when I click import, it just puts the whole path where the class is located and doesn't know what that is but behind it recognizes that there is a class there but can't give import to it. Strange isn't it? I appreciate any kind of solution you can give me, thanks!

package pt.saphirex.sample.android.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import pt.saphirex.sample.shared.Greeting
import android.widget.TextView
import pt.saphirex.sample.android.R

fun greet(): String {
    return Greeting().greeting()
}

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val tv: TextView = findViewById(R.id.text_view)
        tv.text = greet()
        
        pt.saphirex.sample.android.ui.user.home.UserHomeFragmentDirections // <---- Doesn't recognize
    }

}

My software versions are:

  • Android Studio: 4.2.1
  • KMM Plugin: 0.2.5(202-1.5.10-834-IJ)-3

GitHub example: https://github.com/0rangeFox/KMM-Sample

0rangeFox
  • 55
  • 1
  • 9
  • Maybe it is not being generated. That happens sometimes. This will help you. Take a look here https://stackoverflow.com/questions/50686907/safeargs-library-doesnt-generate-direction-class – che10 Jun 05 '21 at 11:13
  • @che10 As I mentioned in my description, this is being generated, it's just that my Gradle Kotlin DSL doesn't seem to do the effect as it should, I've tested the Android Material Components (https://github.com/material-components/material-components-android-examples/tree/develop/Reply) Reply template and it works perfectly with the versions I mentioned. – 0rangeFox Jun 05 '21 at 14:20
  • There is one answer in that link which suggests including `sourceSets` directly into gradle. Maybe try that? – che10 Jun 05 '21 at 15:31
  • Thanks, the solution was exactly that! – 0rangeFox Jun 07 '21 at 16:54
  • I am glad I could help @0rangeFox. I would have answered it but I cannot take credit for it – che10 Jun 07 '21 at 17:03

1 Answers1

2

The solution is basically this, go to android's "build.gradle.kts", and add the following lines inside the "android { }" code:

android {
    ...

    sourceSets {
        getByName("main") {
            java.srcDir("build/generated/source/navigation-args")
        }
    }

    ...
}
0rangeFox
  • 55
  • 1
  • 9