11

I was working on Ubuntu linux and recently i pulled my project and started working on Win10.

From now on i cannot Build/Run my app. There must be a problem with those PNG files in the resources folder.

That is the Error output while trying to build the app :

Executing tasks: [:app:assembleDebug] in project C:\Users\Psz\Documents\Android-ChatRoom-Client

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE

> Task :app:mergeDebugResources FAILED
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-ldpi\\ic_launcher_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-ldpi\\ic_launcher_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-xhdpi\\ic_greensky_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-xhdpi\\ic_greensky_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-hdpi\\ic_launcher_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-hdpi\\ic_launcher_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-mdpi\\ic_greensky_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-mdpi\\ic_greensky_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-mdpi\\ic_launcher_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-mdpi\\ic_launcher_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-xxhdpi\\ic_greensky_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-xxhdpi\\ic_greensky_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-hdpi\\ic_greensky_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-hdpi\\ic_greensky_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Android resource compilation failed","sources":[{"file":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-ldpi\\ic_greensky_background.png"}],"original":"C:\\Users\\Psz\\Documents\\Android-ChatRoom-Client\\app\\build\\generated\\res\\pngs\\debug\\drawable-ldpi\\ic_greensky_background.png: AAPT: error: file failed to compile.\n    ","tool":"AAPT"}

> Task :app:mergeDebugJavaResource

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_greensky_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_greensky_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-ldpi\ic_launcher_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_greensky_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-mdpi\ic_launcher_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xhdpi\ic_greensky_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-hdpi\ic_launcher_background.png: AAPT: error: file failed to compile.
            
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > Android resource compilation failed
        C:\Users\Psz\Documents\Android-ChatRoom-Client\app\build\generated\res\pngs\debug\drawable-xxhdpi\ic_greensky_background.png: AAPT: error: file failed to compile.
            

* 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 1s
10 actionable tasks: 2 executed, 8 up-to-date

build.gradle(:app) file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30

    configurations.all {
        resolutionStrategy.eachDependency{
            DependencyResolveDetails details ->
                def requested = details.requested
                if (requested.group=="com.android.support"){
                    if (!requested.name.startsWith("multidex")){
                        details.useVersion("26.+")
                    }
                }
        }
    }

    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.myname.greenskychatroom"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation files('libs/json-simple-1.1.jar')
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

I don't know what is causing it. I cleaned cache, delete and pull project again. Also i couldn't find a solution online.

Update Found out that Android Studio on Linux(Ubuntu) works just fine and as a matter of fact this error occurs only on Windows' Android Studio..

Panagiss
  • 3,154
  • 2
  • 20
  • 34

7 Answers7

13

I encountered a similar problem to this, and the root cause was that a JPEG file was named with a PNG file extension. Once I fixed the file extension AAPT was happy.

John Michelau
  • 1,001
  • 8
  • 12
3

If some files have been encrypted, AAPT may not work properly. Please check whether the files related to the compilation error are encrypted. In your case, these are PNG files.

Tyler
  • 31
  • 2
  • 3
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/27594874) – BDL Nov 11 '20 at 10:29
  • 2
    OK, maybe it needs to be more clear. If you are using encryption software, please temporarily disable it. Then, please check whether the files related to the error are encrypted (maybe jar, aar, xml, etc.). If they are encrypted, delete these files, download the unencrypted files and try again. E.g: .gradle\caches\transforms-2\files-2.1\4f9c7f78c15bb692cf0895b881aafbad\appcompat-1.2.0\res\anim\abc_fade_in.xml:1: AAPT: error: not well-formed (invalid token). Disable the encryption software, delete the encrypted appcompat-1.2.0, download the unencrypted appcompat-1.2.0, and try again. – Tyler Nov 12 '20 at 02:04
  • @Tyler You're absolutely correct. Of all the things I would have never expected that. In my case, my project was under protected folder and a this along with some things were failing to compile because they're outside libraries and not approved to run inside my directory. Thanks for the help. – eyoeldefare Jun 22 '21 at 00:52
3

im my case i tried to use some png images that i downloaded from whatsapp and they were encrypted.

to fix it follow this steps:

1-open paint 2-open your images 3-save them

and you are ready to go!

yago
  • 59
  • 4
3

If it's an expo app remove whatever png assets you just added. You can rename them as jpg and that would work

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 23 '23 at 14:11
  • This was the point for me. Some assets was named as .PNG but actually it's a JPEG. Renaming it to .jpg and ran `eas build` again solve this issue. Thanks! – rodrix Aug 23 '23 at 20:00
1

I had exactly the same error. Tried everything including pulling my own hear out, but nothing worked. Then someone mentioned running Android Studio as admin would solve the problem... So it has something to do with write access problems. Bingo! Try this:

In windows go to Ransomware protection and disable it!

Then try building again. If that works then use Allow an app through Controlled folder access to give gradle the right access rights. And then enable your Ransomware protection again.

0

In Windows, try to keep your project in a drive apart from windows (C drive). You can use D drive and try keeping the path short (eg. D:\Projects\XyzProject). This might resolve your issue.

m4n0
  • 29,823
  • 27
  • 76
  • 89
0

i face same problem ,and solved .this error is due to windows security , select the file properties which causing issue and unblock it.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 17 '22 at 10:02