androidbuild-errorjavacompileraapt2

Java compiler error, cannot resolve R, build failed


I'm newbie here, I have some problem in my script

Hope you guys help me

In this picture, My R script cannot resolve, and My Build failed, and Java Compiler error

enter image description here

This build failed logs

org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:mergeDebugResources'.
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
   at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.build.gradle.tasks.ResourceException: Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

and this Java Compiler error logs

Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

FYI

I have done all the ways to solve this problem from various sources such as threads on this web, google, and youtube but all did not work I really hope that some of you will be kind enough to help me solve this problem

Thank You


Solution

  • I had the same problem a while ago. Go to Gradle Scripts --> build.gradle (Project: X)

    And look for the line

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    

    I had to replace this line with

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha11'
    

    After changing that line I just synced Gradle, which gave me an error and a prompt to download the files. After that it worked like a charm.