flutter_naver_map icon indicating copy to clipboard operation
flutter_naver_map copied to clipboard

[Android] Execution failed for task ':flutter_naver_map:compileDebugKotlin'.

Open faithinker opened this issue 9 months ago • 12 comments

안녕하세요. 네이버 지도앱 유용하게 잘 쓰고 있습니다. 안드로이드에서 네이버 지도가 동작하지 않습니다.

스크린샷 2024-04-26 오후 4 17 56

minSdkVersion을 명시하라 해서

스크린샷 2024-04-26 오후 4 18 51

이렇게 수정했고 그다음 빌드를 하니 아래와 같이 fail이 뜹니다.


e: file:///jhkim/userName/.pub-cache/hosted/pub.dev/flutter_naver_map-1.2.2/android/src/main/kotlin/dev/note11/flutter_naver_map/flutter_naver_map/view/NaverMapView.kt:134:29 Unresolved reference: style

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':flutter_naver_map:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

NaverMapView.kt 파일 스샷 입니다.

스크린샷 2024-04-26 오후 4 23 59

아래 프로젝트에서 네이버 지도앱 사용 중입니다. https://github.com/faithinker/ddocdoc_clone

flutter clean 이후 flutter run을 해도 똑같습니다. iOS 개발자라서 안드로이드로는 빌드를 잘 안하다가 중간에 안드로이드를 빌드 해보니 빌드가 안됐습니다..

flutter location에서 빌드에러가 나서 https://github.com/Lyokone/flutterlocation/issues/948

app/build.gradle, android/build.gradle, android/settigns.gradle 부분의 gradle. AGP, kotlin 등 버전을 올렸는데 이부분에서 혹시 문제가 되는 것인지도 함께 봐주시면 좋을 것 같습니다.

감사합니다.

faithinker avatar Apr 26 '24 07:04 faithinker

안녕하세요,

compileSdk 34
minSdkVersion 23 

으로 잘 동작하시는지 확인 부탁드리겠습니다.

note11g avatar Apr 26 '24 08:04 note11g

변경했으나 동일한 에러가 발생하고 있습니다.

android/app/build.gradle 파일

def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {   
    flutterMinSdkVersion = '23'
}

def fluttercompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion')
if (fluttercompileSdkVersion == null) {   
    fluttercompileSdkVersion = '34'
}

// TODO: 삭제예정
def printFluttercompileSdkVersion = "fluttercompileSdkVersion: $fluttercompileSdkVersion"
def printFlutterMinSdkVersion = "flutterMinSdkVersion: $flutterMinSdkVersion"

android {
    println printFluttercompileSdkVersion
    println printFlutterMinSdkVersion

    namespace "com.joohyupkim.ddocdoc.ddocdoc_clone"
    compileSdk fluttercompileSdkVersion.toInteger() // flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.joohyupkim.ddocdoc.ddocdoc_clone"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutterMinSdkVersion.toInteger() //flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}


실행결과

fluttercompileSdkVersion: 34
flutterMinSdkVersion: 23
e: file:///Users/jhkim/.pub-cache/hosted/pub.dev/flutter_naver_map-1.2.2/android/src/main/kotlin/dev/note11/flutter_naver_map/flutter_naver_map/view/NaverMapView.kt:134:29 Unresolved reference: style

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_naver_map:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 3s
Running Gradle task 'assembleDebug'...                              3.5s
Error: Gradle task assembleDebug failed with exit code 1
 

flutterMinSdkVersion과 fluttercompileSdkVersion 출력까지 확인해봤습니다.

android {
    compileSdk 34
    defaultConfig {
        minSdkVersion 23
    }
}

로 직접 숫자 명시해봐도 똑같은 빌드 에러가 떴습니다.
커밋 리스트: https://github.com/faithinker/ddocdoc_clone/commits/main

안녕하세요,

compileSdk 34
minSdkVersion 23 

으로 잘 동작하시는지 확인 부탁드리겠습니다.

faithinker avatar Apr 30 '24 04:04 faithinker

android gradle plugin (AGP)의 버전 정보를 받아볼 수 있을까요? 해당 정보는 build.gradle file에 com.android.tools.build:gralde에 명시되어 있습니다!

note11g avatar Apr 30 '24 05:04 note11g

app/build.gradle 파일과 android/build.gradle 파일 두개를 모두 봤지만 com.android.tools.build:gralde 의 경우 아예 명시가 되어있지 않습니다.

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {   
    flutterMinSdkVersion = '23'
}

def fluttercompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion')
if (fluttercompileSdkVersion == null) {   
    fluttercompileSdkVersion = '34'
}

android {
    namespace "com.joohyupkim.ddocdoc.ddocdoc_clone"
    compileSdk 34 // fluttercompileSdkVersion.toInteger() // flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.joohyupkim.ddocdoc.ddocdoc_clone"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 23 //flutterMinSdkVersion.toInteger() //flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}

app/build.gradle 파일 전문 소스코드입니다.

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.2.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

include ":app"

AGP의 경우 빈값으로 뜨고 있으나 스크린샷 2024-04-30 오후 8 45 51 추가를 해줘도 스크린샷 2024-04-30 오후 8 53 36

스크린샷 2024-04-30 오후 8 53 50

첫번째 사진과 같이 빈 값으로 뜹니다.

NDK 설치버전 스크린샷 2024-04-30 오후 8 47 15

Android SDK와 NDK 설정 local.properties에서 직접 명시 = Finder와 일치 스크린샷 2024-04-30 오후 8 52 30

안드로이드스튜디오에서 ndk와 gradle version 8.2로 설정하고 나니 다른 에러가 뜨는데... 이거는 naver map 하고 연관 없어보이네요...

One or more plugins require a higher Android NDK version.
Fix this issue by adding the following to /Volumes/samsung/Flutter/myGit/ddocdoc_clone/android/app/build.gradle:
android {
  ndkVersion "25.1.8937393"
  ...
}


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > An issue was found when checking AAR metadata:

       1.  Dependency ':flutter_local_notifications' requires core library desugaring to be enabled
           for :app.

           See https://developer.android.com/studio/write/java8-support.html for more
           details.

gradle-wrapper.properties 입니다. 스크린샷 2024-04-30 오후 9 03 46

동료 안드로이드 개발자분한테 여쭤봐도 잘 모르시더라구요... 정 안되면 새 프로젝트에서 다시 네이버 맵 pub 추가해서 해볼려고 합니다...

faithinker avatar Apr 30 '24 12:04 faithinker

원인을 찾았습니다. android gradle plugin 8.0부터는 android.nonTransitiveRClass의 기본값이 false에서 true로 변경됩니다. 해당 속성은 현재 모듈에 정의된 R Class가 아니면 생성하지 않도록 하는 옵션입니다만, 이것의 기본값이 true로 변경되며 기존 flutter_naver_map에서 flutter앱의 R을 통해 참조하고 있던 appcompat 테마 강제 활성화 기능이 R.style을 더 이상 flutter_naver_map 모듈에서 생성하지 않음에 따라 오류가 발생하는 것입니다. (Reference: Android Developers)

이 속성의 기본값이 바뀐 이유는 모듈화로 apk를 최대한 쪼개서 용량을 줄이겠다는 목적으로 보입니다. (android developer page comment: AGP 8.0은 현재 모듈에만 정의된 리소스의 R 클래스를 생성합니다.)

따라서 임시 방편으로 빌드되도록 하는 조치는 다음과 같습니다. (앱에 따로 오류나 악영향을 초래하지는 않습니다. 안심하세요)

[Flutter 프로젝트 루트]/android/gradle.properties

// ... 여러 옵션들이 이미 있을 것입니다. 아래에 추가하세요.
android.nonTransitiveRClass=false

일단 오늘은 자야해서, 여기까지만 해두고 라이브러리 단에서 해결할 수 있는 방법이 있는지 찾아보도록 하겠습니다.

두가지 방안을 생각중입니다.

  1. R.style 속성 이용하지 않기 (instead, provide open legal/license/... activity method + logo touch detecting)
  2. nonTransitiveRClass 옵션 서브 모듈 단에서 조작 가능한지 살펴보기

note11g avatar Apr 30 '24 18:04 note11g

android.nonTransitiveRClass=false

코드 추가하니 정상적으로 안드로이드에서도 빌드가 가능합니다.

위에서 언급했던 flutter_local_notifications 빌드 에러는 pub에서 제거하니 정상적으로 빌드 되고요... => 이것도 그쪽 오픈소스 가서 이슈 올려야 하는데.. 😂😂

스크린샷 2024-05-01 오후 2 10 45

앱에 따로 오류나 악영향을 초래하지는 않습니다.

사이드 프로젝트로 연습 공부중인 부분이라 괜찮습니다...

도움주셔서 감사합니다.

faithinker avatar May 01 '24 05:05 faithinker

해당 이슈는 해야할 작업으로 등록해두기 위해 다시 열었습니다.

note11g avatar May 01 '24 06:05 note11g

TODO

  • [ ] naver logo button deactivate & draw on flutter side
  • [ ] make naver map license view calling api on NaverMapApi instance method

note11g avatar May 27 '24 05:05 note11g

안녕하세요. 질문자님과 동일한 오류가 발생해서 android.nonTransitiveRClass=false를 추가했는데도 안드로이드에서 빌드가 되지 않습니다. 혹시 추가적인 수정사항이 있을까요?

스크린샷 2024-07-16 오전 11 54 01

dohyxx avatar Jul 16 '24 02:07 dohyxx

@dohyxx 어떤 오류로 인해 빌드되지 않는지에 대한 정보가 필요합니다. 빌드 실패에 대한 전체 로그를 남겨주시기 바랍니다.

note11g avatar Jul 18 '24 09:07 note11g

@dohyxx 어떤 오류로 인해 빌드되지 않는지에 대한 정보가 필요합니다. 빌드 실패에 대한 전체 로그를 남겨주시기 바랍니다.

@note11g 안녕하세요. 답변 감사합니다.

현재 naver map과 관련된 .kt 파일들을 참조하지 못한다는 오류와 함께 위와 동일한 flutter_naver_map:compileDebugKotlin 오류가 발생하고 있습니다. 안드로이드는 따로 설정할 부분이 없는 걸로 알고있는데, 놓친 부분이 있을까요?

스크린샷 2024-07-19 오전 10 29 09 스크린샷 2024-07-19 오전 10 39 06 스크린샷 2024-07-19 오전 10 22 47

android/app/build.gradle 파일

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
    flutterMinSdkVersion = '23'
}
def fluttercompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion')
if (fluttercompileSdkVersion == null) {
    fluttercompileSdkVersion = '34'
}

def kakaoNativeAppKey = localProperties.getProperty('KAKAO_NATIVE_APP_KEY')

android {
    namespace "kr.co.vuka.jobs"
    compileSdk fluttercompileSdkVersion.toInteger()
    ndkVersion "25.1.8937393" //flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "kr.co.vuka.jobs"
        minSdkVersion flutterMinSdkVersion.toInteger()
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        buildConfigField "String", "KAKAO_NATIVE_APP_KEY", kakaoNativeAppKey
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the
 release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}

dohyxx avatar Jul 19 '24 01:07 dohyxx

@dohyxx 해당 이슈는 이 이슈와는 다른 이슈인 것으로 보입니다. 이 이슈 스레드에서 다루고 있는 주제는 AGP 새 버전에서의 정책 변경으로 인해 다른 모듈의 R Class를 참조하지 못하는데서 비롯되는 이슈입니다. 오류 내용을 캡쳐가 아닌, 전체 텍스트를 복사하여 새 이슈를 열어주시기 바랍니다.

지금 주어진 정보만으로 말씀드릴 수 있는 방안은 다음과 같습니다. 최신 버전으로 업데이트 후, 버전업 가이드를 진행해주세요.

note11g avatar Jul 24 '24 08:07 note11g