Android Studio AAPT1/AAPT2 errors - android

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.

Related

How to fix configuration of ':app:kaptDebugKotlin'

I'm having a problem getting my project to build. I get the message:
"A problem was found with the configuration of task ':app:kaptDebugKotlin'.
Cannot write to file 'C:\Workspace\depot\RM12\Mobile\AppSuite\Android\Working11\AppSuite\app\build\intermediates\data-binding\debug\bundle-bin' specified for property 'dataBindingArtifactOutputDir' as it is a directory"
This build issue won't occur for my first build after I clean the project, but if I try to build a second time I get this error. Which makes me do a clean and rebuild every time I need to run the project.
It occurs in some branches for me, while others don't seem to have this issue, and my coworkers have never seen this error. Which likely means this has something to do with my workspace.
I've done some research but haven't come across anything that has helped at all.
Please help me!!!

error: cannot find symbol class DataBindingComponet after merge two branches

I got the very weird problem, I have two branches and working fine separately. after the merge, All conflicts are resolved carefully many times. But every time we run the project this 3 error will come and No stack trace. T
error: cannot find symbol class DataBindingComponent
error: cannot find symbol class DaggerLoginComponent
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException:
Compilation failed; see the compiler error output for details.
There is something wrong that stop annotation processor to stop compilation but we didn't find any reason However we checked all the files manually but Not know How we can debug the issue and Identify the root cause of the issue. Anyone who know how we can track why annotation processor is not generating the class.
We have tried listed methods.
Clean -> Rebuild -> Invalidate Restart -> Delete all temporary files.
run build with this command ./gradlew clean assemble --stacktrace --debug
checked every resource and java files manually to find the issue.
We have used below library
lombok 1.16.20, databinding , dagger 2.16 that are using annotation processor
We have conflict in dimen, string and style files. that are resolve very carefully.
If need any more info I would provide.
Updated: Finally get a solution There was a private static import in
other class that causes this problem
Make Sure You don't have any java compiler issue, Even small syntax issue will not compile your binding and I don't know why the error is not printing in logcat. Hope It will resolve in the updated android studio.
Adding up to comments, both times this happened to me, it was related to dagger.
unresolved import in a dagger module class. Spent 4 hours to find this
#Inject annotation on a class that was made abstract. Spent 2 days to find this
The workflow into knowing W*F is wrong, is:
in a small project, inspecting all your classes and layouts might be a viable choice
if you can, go back in commits to reach the last working point, and see from there. This is almost useless advice, because this nasty thing typically happens when you are in the middle of some kind of refactoring
create a destructive branch & do whatever is possible to use the old databinding compiler, android.databinding.enableV2=false. Doing this might require you to remove modules, remove new features that you were using (e.g. experimental databinding in non-feature modules), probably downgrade AGP. But it's worth it, because the old databinding compiler will actually tell you the error instead of this cannot find symbol mess.
Good luck with this exhausting process, and if you can, please file a bug report to databinding guys.
This is most weird problem that i faced before this month. First of all Data Binding is not as mature that it show you all errors with reach point in Error Logs.
However there are some issues that are not caught by lint and lead to errors in all classes related to binding.
Causes:
When there is a field defined in layout component binding that is not available in your model class.
When you have some invalid import in your data binding layout.
Solution
Check your layouts first for invalid imports. Because that will not show in error log.
If you don't find anything, then check your all layouts carefully for the missing model fields, If there is some field not present in model class, and used in layout then you will not get appropriate error.
If this does not help then check your Binding Component names are correct. Because if your partner renamed a layout then you should change its relevant LayoutBinding name in Activity or Fragment.
These solution helped me always to overcome this issue.
Renaming the xml files to another name and check if binding works once it works rename it back to the one that was used.
Hope this may help you

Aapt2 exception even after disabling it

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.

AAPT2 error - appcompat-v7 files not found in mergeDebugResources

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.

Could Not parse Array item

I was working on my android studio when this error appeared in I think gradle-values files.
here is what messages say
/home/aayush/.gradle/caches/transforms-1/files-1.1/play-services-
cast-framework-
11.8.0.aar/32e84c2c10bff7a8fd7f6321ccbff502/res/values/values.xml
Error:(5, 1) error: could not parse array item.
Error:java.util.concurrent.ExecutionException:
com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for
details
I tried deleting the whole build folder,.gradle folder, cleaning and rebuilding folder, invalidating caches and restarting android studio but, this error comes again and again. I am using android studio 3.1, the latest one. please help. If you need any other detail, just tell me. i am facing this problem for the first time, so, dont know what to post.
I was facing that issue too.
That may be invoked in several reasons.
In my case, I got the error because of the 'strings.xml' file has like this components
<string name="today_string">'today'</string>
this mistakes made this error, and I converted 'today' to \'today\'
And it solved my issue. Refer.

Categories

Resources