안드로이드/오류, 삽질 및 해결방법

[Android/Kotlin] Navigation Safe Args 에러 해결

감자 바보 2022. 2. 17. 17:51
반응형

프레그먼트 이동 및 데이터 전달을 하기 위해 navigation safe arg 라이브러리를 사용하면서 에러가 발생하였다. 

 

발생 오류

Class 'ActionGlobalNavigationPost' is not abstract and does not implement abstract member public abstract fun getActionId(): Int defined in androidx.navigation.NavDirections
'actionId' overrides nothing
'arguments' overrides nothing

앱 실행결과로 위와 같은 에러 메시지가 출력되며 앱이 실행이 되지 않았다.


문제 원인

프로젝트 수준의 build.gradle과 앱/모듈 수준의 build.gradle에서 다른 버전을 사용하여 발생한 문제였다.

아래 코드에서 프로젝트 수준에서는 2.4.0을, 앱/모듈 수준에서는 2.3.5를 사용하였다.

build.gradle(프로젝트)

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

build.gradle(앱/모듈)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs.kotlin'
}

dependencies {
    //프레그먼트 이동시 데이터
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
}

해결 방안

앱/모듈 수준의 build.gradle의 코드를 2.4.0으로 변경하니 정상적으로  앱이 실행되었다.

implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'

참고 사이트

Android studio build error in navigation component, action is not abstract and does not implement abstract member actionID - Stack Overflow

 

Android studio build error in navigation component, action is not abstract and does not implement abstract member actionID

Out of nowhere, the build is crashing with a strange error related to the navigation component even though it used to work before, the error is in the generated class, in my case

stackoverflow.com