android-studiojavacompiler

Java compiler error in Android Studio


I've just installed Android Studio and I've spent a good couple of days trying to set it up but I got errors here and there.

My current error is:

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

It looked through similar questions on SO, but I couldn't find a helpful solution.

I have Android Studio Version 3.1.3

I have the following in my build.grade file, but the problem still exists.

compileSdkVersion 27

buildToolsVersion '27.0.3'

enter image description here

I can solve this issue by adding the following line into gradle.properties file with a warning The option 'android.enableAapt2' is deprecated and should not be used anymore:

android.enableAapt2=false

But I get another error instead:

No resource identifier found for attribute 'appComponentFactory' in package 'android'

Solution

    1. Go to https://developer.android.com/studio/releases/platform-tools
    2. Click on SDK Platform-Tools for Windows for downloading
    3. Unzip the archive and add it to your /Android/platform-tools directory
    4. Restart Android Studio

    Also, you can try to change Android Emulator to a different from the default one.