Flutter image_gallery_saver 패키지 빌드 에러 해결방법
image_gallery_saver 패키지 빌드 에러 시 발생하는 에러를 해결해 봅시다.
image_gallery_saver는 flutter에서 미디어 파일을 갤러리에 저장하는 기능을 제공하는 패키지입니다.
image_gallery_saver | Flutter package
A flutter plugin for save image to gallery, iOS need to add the following keys to your Info.plist file.
pub.dev
그러나 현재[2025. 02] 해당 패키지를 추가하여 빌드할 경우
다음 에러가 발생하며 빌드가 되지 않습니다.
Incorrect package="com.example.imagegallerysaver" found in source AndroidManifest.xml: /Users/amuz/Desktop/image_gallery_saver-2.0.3/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.example.imagegallerysaver" from the source AndroidManifest.xml: /Users/amuz/Desktop/image_gallery_saver-2.0.3/android/src/main/AndroidManifest.xml.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':image_gallery_saver:processDebugManifest'.
> A failure occurred while executing cohttp://m.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
Incorrect package="com.example.imagegallerysaver" found in source AndroidManifest.xml: /Users/amuz/Desktop/image_gallery_saver-2.0.3/android/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="com.example.imagegallerysaver" from the source AndroidManifest.xml: /Users/amuz/Desktop/image\_gallery\_saver-2.0.3/android/src/main/AndroidManifest.xml.
BUILD FAILED in 866ms
Error: Gradle task assembleDebug failed with exit code 1
최신 Android Gradle 플러그인의 문법이 변경되면서
더 이상 package 옵션을 제공하지 않기 때문에 발생하는 에러입니다.
따라서 해당 패키지의 AndroidManifest.xml 에서 해당 옵션을 namespace로 변경해야 합니다.
해결 방법
1. package를 namespace로 변경하기
Mac OS에서 image_gallery_saver 패키지의 디렉터리는 아래 경로에 존재합니다.
/.../.pub-cache/hosted/pub.dev/image_gallery_saver-2.0.3
해당 경로의 android/src/main/AndroidManifest.xml 에서
package를 android:namespace로 변경합니다.
# 변경 전
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imagegallerysaver">
</manifest>
# 변경 후
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:namespace="com.example.imagegallerysaver">
</manifest>
2. compileDebugKotlin 에러 해결방법
XML 변경 후에도 다음 에러가 발생할 수 있습니다.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':image_gallery_saver:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
해당 에러는 Java와 Kotlin의 JVM 타깃 버전 불일치로 인해 발생하는 문제입니다.
따라서 Kotlin 컴파일 버전을 현재 사용 중인 자바 버전에 맞게 버전을 지정해줘야 합니다.
android/build.gradle 파일을 수정하여 자바 버전을 명시할 수 있습니다.
저는 JAVA 17으로 설정하였습니다만 개발 환경에 맞게 변경해야 합니다.
group 'com.example.imagegallerysaver'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'co[http://m.android.tools.build:gradle:7.3.0'](http://m.android.tools.build:gradle:7.3.0')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
namespace = "com.example.image_gallery_saver"
// SDK 버전 지정
compileSdkVersion 30
// 자바 버전 지정
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
// 코틀린 자바 버전 지정
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
전체 코드
https://github.com/JisooOvO/image_gallery_saver_fixed_gradle
GitHub - JisooOvO/image_gallery_saver_fixed_gradle
Contribute to JisooOvO/image_gallery_saver_fixed_gradle development by creating an account on GitHub.
github.com
'Flutter > Package' 카테고리의 다른 글
[Flutter] path_provider 패키지 정리 (1) | 2025.02.16 |
---|---|
[Flutter] Camera 패키지를 이용하여 사진 촬영 및 갤러리 저장 기능 구현하기 (1) | 2025.02.16 |