I have an old android project that is having compilation problems. I've added a gradle.properties file to root with a single line:
android.enableAapt2 = false
However, I'm still getting this error:
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT error: check logs for details
Which doesn't make sense to me because I've disabled aapt2 and it still seems to be using it. In addition, I've checked every log I can find with no additional information found on what is actually breaking.
As for your first question, the build is giving you an AAPT error, which might be coming from AAPT(1), not just AAPT2, that's why disabling AAPT2 doesn't "fix" it.
Secondly, disabling AAPT2 is not a solution. AAPT2 is telling you there's something wrong with your files. It fails the build early so that your app doesn't crash at run-time (which AAPT would silently allow).
Lastly, it's possible that you modified something in between the builds or that it didn't build in the past either. A way to figure out what the problem is, is to check the logs. If you're having trouble finding them in Android Studio (they will be in different places for different versions of Android Studio, Android Gradle Plugin and Gradle), an easy way to generate it is to go to the Terminal window in Android Studio and run "gradlew clean assembleDebug". The errors from AAPT/AAPT2 should be just above the stacktrace.
Related
In old times of Android Studio, when I had compilation error and something was wrong resources I could quickly click on the error and was pointing me to the file. Now I’m getting error com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed but there is nothing to click that takes me quickly to the file to fix an error. Can I find these links somewhere?
You can find the issue on your project using the build report on Android Studio. You just need to switch between views:
This view will show the gradle build logs, and most likely will contain the resources issue.
I have a Hudson build job that's failing with the error
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
and in the logs, lots of lines like this:
C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\3bbc697d357b69b5ea5f78a35f99a514\res\color\abc_hint_foreground_material_dark.xml: error: file not found.
I've found a few questions on AAPT2 errors like this, for example this and this but they don't seem to have a fix.
So why is the build failing?
As per the first linked question, disabling AAPT2 seems like a bad idea, as AAPT might be removed at some point in the future.
The second linked question at least gives a clue, with the accepted answer there being that that version of gradle doesn't handle non-ASCII characters in the .gradle cache path. But in our case, there aren't any non-ASCII characters in the cache path being logged.
In fact, from the logs, gradle is looking for the cache inside C:\Windows\System32\config\systemprofile\.gradle, which is only accessible with admin privileges. Not somewhere we want to be caching libraries.
This answer, along with this post on the gradle forums are what led me to the solution. Short version is, by default gradle caches downloaded libraries in the user area, and there seems to be a bug in Java where it will incorrectly determine the users home directory. This results in the gradle cache being put somewhere it really shouldn't be.
To fix the problem, then, we just need to set gradle's user home directory. This blog post has a bunch of ways to do that. One way is to create a GRADLE_USER_HOME environment variable, which has the advantage of applying to all gradle builds on the machine.
I have two separate errors relating to AAPT:
The first:
AAPT2 error : check logs for details
The second:
Failed to execute aapt
The first error can be solved by adding android.enableAapt2=false into the gradle.properties file, but this causes the second error to occur.
It appears as if though solving the first means the second never can be solved.
What can I do to get around this?
It seems to me that you are just avoiding the first error by disabling it. That will obviously cause problems if you need aapt (or more specifically, aapt2) to run.
As per my understanding, aapt1 will be removed at some point, so it is probably a bad idea to disable aapt2 anyway, as that will be the default in the future.
Instead, try to follow the advice given, and look for the real error in the Aapt log. Most likely there will be something wrong with one of your resource files.
PS: If you run your command with --stacktrace, it might output more useful information.
i have a strange error with AAPT2 iin Android Studio. I think it has something to do with german special characters in my account name in windows.
If i set my gradle to version 3.0.1 and also set android.enableAapt2 to false everything works fine. But since i researched, setting the option is not a solution to the problem.
Now if i set the gradle version to 3.1.2 and remove android.enableAapt2 from the properties i get the following error message:
And this one:
One way to solve the problem was to create a new account in windows without special chars in the name. It compiled and did run very well. I really tried everything in the web but could not find a solution to the problem.
Maybe you can help me.
First of all check your build log botom of the build section you shared whether any error related to your project showing or not. If error showing then fix those. Build and run again and fix all the error comes up. It will eliminate aapt2 issue without changing android gradle plugin.
Secondly if there is not any project related error showing in the build log but still its showing aapt2 error then you can fix it by following below steps.
Update your android gradle plugin in your project level build.gradle file like below:
classpath 'com.android.tools.build:gradle:3.2.0-alpha13'
Now update android.enableAapt2=true. Then check and build your project.
I am trying to install an FPC program on to android device by following this article.
While creating .dex file by giving the input as .jar (classes.jar) file, it is giving the following error.
MacBookPro:src Sreehari$ /Library/android-sdk-macosx/build-tools/23.0.2/dx --dex --output=bin/classes1.dex eu/blaisepascal/skeletonapp/skeltonapp.jar
Uncaught translation error: com.android.dx.cf.code.SimException: local 0002: invalid
1 error; aborting
I have seen on internet that it is because of not giving pro-guard, is it true? How do I give pro-guard?
It can also happen when you have "Instant Run" enabled
Not sure what you mean by giving pro-guard but I will give a general answer to the problem as I encountered the same error in the past and this is what worked for me.
The simplest way of solving this compilation error is by setting minifyEnabled to false in your build's gradle file. This solution will skip running pro-guard among minifying the apk size, something that's not acceptable in many situations.
The more general solution is to update google play services or find a library used in your project that's using an old version of it.
Try to disable Instant Run in Android Studio
Open the Settings or Preferences (Mac) dialog.
Navigate to Build, Execution, Deployment > Instant Run.
Uncheck the box next to disable Instant Run.