관리 메뉴

나만을 위한 블로그

[Android] Navigation 사용 시 FragmentDirections가 자동 생성되지 않을 때 본문

Android

[Android] Navigation 사용 시 FragmentDirections가 자동 생성되지 않을 때

참깨빵위에참깨빵 2022. 12. 9. 02:00
728x90
반응형

제트팩 네비게이션을 쓰려고 프래그먼트들과 nav_graph.xml 등 이것저것 다 준비하고 프래그먼트에서 Directions를 사용하려는데 Directions 밑에 빨간 줄이 생기고 갖다대면 Unresolved reference 에러가 발생하는 경우가 있다.

해결법은 앱, 프로젝트 gradle 파일을 각각 확인해서 없는 부분만 채우면 된다. 안드로이드 스튜디오 Chipmunk 기준으로 프로젝트 gradle은 아래와 비슷한 형태일 것이다.

 

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        navigation_version = '2.4.2'
        hilt_version = '2.40.5'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

다른 건 무시하고 네비게이션 관련 부분만 채워주면 된다.

앱 gradle은 아래와 같다.

 

plugins {
    .
    .
    .
    id 'androidx.navigation.safeargs.kotlin'
}

def navigation_version = '2.3.2'
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

 

plugins 안에 네비게이션 관련 한 줄 써주고 의존성 버전과 문구들을 확인한다.

이렇게 하고 클린 -> 리빌드하니 정상적으로 생성된다.

 

 

정리)

 

앱, 프로젝트 gradle에 없는 게 있을 수 있으니 확인하고 채워넣어 보자

반응형
Comments