[안드로이드] com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed 오류 해결하기 (error: failed to read PNG signature: file does not start with PNG signature. 이미지 확장자 오류 처리)
빌드 버전 상향 후 몇 개의 이미지를 추가 후 테스트를 위해 휴대폰에서 실행하는 경우는 오류가 발생하지 않았다.
그러나 릴리즈 버전으로 빌드하는 경우에 발생하는 오류이다.
파일 이름이 잘 못 되었나 싶어 확인했으나 png파일로 되어있고 존재했다.
Execution failed for task ':app:mergeReleaseResources'.
> 8 exceptions were raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
C:androidAndroidStudioProjectscomappsrcmainresdrawable-xxhdpii_s_r.png:
error: failed to read PNG signature: file does not start with PNG signature.
C:androidAndroidStudioProjectscomappsrcmainresdrawable-xxhdpii_s_r.png: error:
file failed to compile.
[build.gradle] 파일 정보
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
[buildgradle (:app) 파일 정보]
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
// buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.test"
minSdkVersion 26
targetSdkVersion 30
versionCode 8
versionName "1.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//
// kotlinOptions {
// jvmTarget = "1.8"
// }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'com.android.support:appcompat-v7:29.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-ads:18.3.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'androidx.work:work-runtime:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.0.4')
// Declare the dependency for the Cloud Firestore library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-firestore'
// Declare the dependency for the Firebase Authentication library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth'
// Also declare the dependency for the Google Play services library and specify its version
// implementation 'com.google.android.gms:play-services-auth:20.0.1'
//MIT progressbar
//https://github.com/ybq/Android-SpinKit
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
//위치는 dependencies 아래쪽에 반듯이 위치시킬것
apply plugin: 'com.google.gms.google-services'
오류 해결을 위해 gradle.properties 설정파일 열고 android.enableAapt2=false 속성을 추가해주었다.
오류는 여전히 해결되지 않았다.
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
android.enableAapt2=false
오류 원인은 이미지 형식이 PNG가 아닌데 파일의 확장자가 PNG로 되어 있기 때문이다.
그래서 혹시나 해서 그림판에서 이미지를 열고 png파일로 저장했다. 그럼에도 불구하고 계속 동일한 오류가 발생 중이다.
원래파일은 확장자가 HEIC인 파일이다. png로 변경했는데…. 뭔가 바뀌지 않는 정보가 존재하는 것 같다.
그래서 아래 사이트에서 png파일을 jpg로 일괄 변경 후 다운 받아서 처리하였다.
오늘 새롭게 알게된 사실은 이미지확장자 중에 HEIC, WebP가 있다는 것이다.
150개가 넘는 이미지를 일일이 변경하는 것은 너무나도 시간낭비, 인력낭비임으로
아래 사이트를 이용하여 일괄로 변경하였다.
HEIC 사진을 JPEG 형식으로 변환하세요
소프트웨어를 설치할 필요 없이 빠르고 쉽게 온라인으로 HEIC 사진들을 JPEG 형식으로 변환하세요
heic2jpg.com
WebP 파일을 JPEG로
WebP 이미지를 JPEG 포맷으로 온라인에서 올바른 압축기법을 사용하여 무료 전환 하세요
webptojpeg.com
PNG 파일을 JPEG로
PNG 이미지를 JPG 포맷으로 온라인에서 올바른 압축기법을 사용하여 무료 전환 하세요
png2jpg.com
JPEG 파일을 PNG로
JPG 이미지를 PNG 포맷으로 온라인에서 올바른 압축기법을 사용하여 무료 전환 하세요
jpg2png.com
온라인에서 Word 파일을 JPEG 이미지로 변환하기
Word파일에서 최적의 JPEG 이미지 설정으로 변환하는 공짜 온라인 서비스. 대용량 파일을 50MB까지 변환할 수 있습니다.
wordtojpeg.com
온라인으로 JPEG 이미지 파일을 Word문서로 변환하기
어떤 소프트웨어를 설치할 필요없이, 빠르고 쉽게, 모든 이미지를 Word로 변환시키기
jpegtoword.com
오늘도 오류가 발생하여 또 하나는 배우는구나…..
[REFERENCE]