AAPT2 compile failed: invalid dimen on Android 3.0 Canary 1
Solution 1
The workaround is to switch your development machine to a locale which uses "." as a decimal mark.
It can be changed the following way:
Solution 2
Below are mentioned four different solutions: A, B, C, and D; pick one that suites you:
A) Fixing Android Studio via Ubuntu .desktop launcher file
This is an Ubuntu-only alternative to the general approach on Fixing Android Studio (see below). Note that you may still want to implement the part about Fixing the shell, and perhaps even revert any modifications to studio.sh
to fully confirm this fix.
I got tired of patching my studio.sh
for every canary update, so I came up with a better solution that eliminates this step. It works on Ubuntu and simply involves creating a .desktop launcher that sets the sick environment variable in question.
Make a note of where your Android Studio 3 is installed, e.g.
~/opt/android-studio-3
.-
Prepare your local icon and applications directory, in case the don't already exist:
mkdir -vp ~/.local/share/icons ~/.local/share/applications
-
Create an Android Studio 3 icon that will make your launcher stand out from the default icon and save it into
~/.local/share/icons/android-studio-3.png
. Or you can use the one I made by rubbing a piece of cheese on the original (~/opt/android-studio-3/bin/studio.png
): -
Create an Android Studio 3 launcher file by copy and pasting this into a shell:
cat <<-EOF > ~/.local/share/applications/android-studio-3.desktop [Desktop Entry] Version=1.0 Type=Application Name=Android Studio 3 Icon=android-studio-3 Exec=env LC_NUMERIC="en_US.UTF-8" opt/android-studio-3/bin/studio.sh "%f" Categories=Development;IDE; Terminal=false StartupWMClass=jetbrains-studio EOF
-
Make it executable:
chmod +x ~/.local/share/applications/android-studio-3.desktop
Now for the tricky part. Ideally you should be able find, start, and create shorts for Android Studio 3 from the Dash:
But personally, I almost always have trouble getting Ubuntu to detect my new or changed .desktop files. One solution is to log out and back in again. If anyone knows how to force a rescan please let me know!
B) Fixing Android Studio start script
Here's an easy, elegant, and semi-permanent fix: Only change the locale of Android Studio itself by modifying its startup script:
Edit
studio.sh
e.g.~/opt/android-studio/bin/studio.sh
or whatever your installation path may be.-
Somewhere at the top of the file, below
#!/bin/sh
and before the first lines of code appear, add this:LC_NUMERIC="en_US.UTF-8"
.Here's the top part of my
studio.sh
for completeness:#!/bin/sh # # --------------------------------------------------------------------- # Android Studio startup script. # --------------------------------------------------------------------- # LC_NUMERIC="en_US.UTF-8" message() { TITLE="Cannot start Android Studio" ...
Restart Android Studio
A note on Upgrading Android Studio or Gradle
When you later upgrade your Android Studio installation, it will detect that you've modified studio.sh
. You should let the installer replace the file, and afterwards perform the patch again as described above. Finally restart Android Studio, and you'll be ready again. The other solutions are not affected by this.
C) Fixing the shell; Gradle, Jenkins, all that
Building from the shell using gradlew
also requires the fix to be applied. This only affects the shell and not Android Studio. Pick one:
-
Either specify the the fix on every invocation like this:
LC_NUMERIC="en_US.UTF-8" ./gradlew clean assDebug
-
Or to make this permanent for the project, edit the
gradlew
file in the root of the project and somewhere at the top add this:LC_NUMERIC="en_US.UTF-8"
Like here:
#!/usr/bin/env bash ################################################################################ ## ## Gradle start up script for UN*X ## ################################################################################ LC_NUMERIC="en_US.UTF-8" # Add default JVM options here. You can al... DEFAULT_JVM_OPTS="" APP_NAME="Gradle" ...
-
Or you can of course also add a global and permanent fix though the use of an alias,
gr
:cat <<EOF>>~/.bash_aliases # Fixing Android Studio 3 Canary bug https://stackoverflow.com/a/44304075/2412477 alias gr='LC_NUMERIC="en_US.UTF-8" ./gradlew' EOF
Note this is how bash shell aliases are added on Ubuntu; if you're on a different OS perhaps you should append to ~/.bashrc or ~/.profile instead.
Then start a new shell and now instead of invoking
./gradlew
use the new aliasgr
:gr clean assDebug
The clear disadvantage of #2 is that this has to be applied to all projects manually. The advantage, I think, is that this will automatically be overwritten when a new gradlew is installed, much like studio.sh
gets replaced, so you get to test if the bug has been fixed =)
D) Disabling APPT2 all together
Personally I wouldn't do this, but I've added it for completeness since it definitely is a way to make appt2 stop giving errors. Add this line to your gradle.properties
: android.enableAapt2=false
Solution 3
I solved this problem by adding the following line to the gradle.properties files
android.enableAapt2=false
Solution 4
Make sure you are not adding any units(dp) when using format="float"
I was facing the same problem because I auto-generated dimens using Android Studio using Extract dimen resource
and it added unit type like:
<item name="margin_top" type="dimen" format="float">51.75dp</item>
It should be:
<item name="margin_top" type="dimen" format="float">51.75</item>
Solution 5
This issue has been fixed in the newest Android Studio stable. Upgrading your Android Studio to 3.0 should solve this issue for you (also no need to disable AAPT2).
sposnjak
Updated on July 08, 2022Comments
-
sposnjak almost 2 years
I am playing around with Instant Apps for Android.I installed all the correct packages and tired to create new Application with Instant App support (checked the box for Instant App when crating new application). The problem is that I always run into a problem with compile tools. Does anybody else have this problem and was able to find any workaround.
My environment:
- Android Studio 3.0 Canary 1
- Compile SDK: 25
- Build Tools: "26.0.0 rc2"
- Gradle plugin:3.0.0-alpha1
- Gradle: tried both gradle-4.0-milestone1 and 2
- Java 1.8/1.7
- OS: tried both Windows 10 and Linux Ubuntu 16.4 LTS
The error:
Error: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed: aapt2 compile -o /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/res/merged/androidTest/debug /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml Issues: - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:520 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:521 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:568 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:594 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:595 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:597 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:598 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:599 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:600 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:601 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:602 invalid dimen - ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:603 invalid dimen :feature:mergeDebugAndroidTestResources FAILED
The line in question contains (520):
<item format="float" name="abc_disabled_alpha_material_dark" type="dimen">0.30</item>
Hopefully I provided enough information to you to resolve the problem. Thank you.
-
Salim about 7 yearsThis worked for me. Apply system-wide was not necessary. But restarting Android-Studio is not enough. You need to log-out and log-in again (or restart your system) to make the changes active for gradle build.
-
sposnjak about 7 yearsIt works! For linux you should do: export LC_NUMERIC="en_US.UTF-8" and then start Android Studio in the same prompt
-
rzehan about 7 yearsI added export LC_NUMERIC="en_US.UTF-8" to the beginning of my studio.sh and it works fine. I certainly wouldn't change my system wide locale just to work around some bug.
-
Stephan Henningsen about 7 years...wat? Recommending someone to change their system wide locale just because of one bug in one app is crazy. It will impact how your date is formatted e.g. in email clients, even language and pretty much everything else too.
-
saturov about 7 years@StephanHenningsen what did you expect from alpha-release? this is just workaround if you are strongly need to use this version of IDE
-
Stephan Henningsen about 7 yearsYou misunderstood; I'm not commenting on the bug itself; I'm commenting on the work-around.
-
lelloman about 7 yearsthis seems a much better workaround than the accepted answer
-
vladaman about 7 yearsFor some reason this does not work for me. I got Android Studio 3.0 Canary 3 and after setting all this the merge problem persists. My locale is en_US.UTF-8
-
user2520215 about 7 yearsWell I'm on windows. Any suggestions?
-
lelloman about 7 yearsI just updated to canary 3 and came back here to copy paste again, it's still working for me
-
aberaud about 7 years@vladaman This fixes the obvious floating point bug, however Android Studio 3.0 canary 3 is still stricter than before, and some bugs in your resource files that where previously accepted will now cause a merge error. Note that as of today, the design library preview is bugged and won't build on Android Studio 3.0 canary 3.
-
Romuald DANSOU about 7 years@EugenPechanec Yes
-
Eugen Pechanec about 7 yearsThat doesn't make any sense. If you were missing the repository when you needed it, you wouldn't get as far as merging resources. Build would fail with missing dependencies. If you didn't need the repository, having it specified wouldn't change a thing. OP wouldn't get this far in build process if they haven't already included google maven repo reference in their project. Your answer does not provide solution to the problem at hand. You must have made other changes too.
-
Maxr1998 about 7 yearsStill happening on canary 4, and because I use the design library it also happens with the fix.
-
Stephan Henningsen about 7 yearsI don't see how installing these packages should fix the problem at hand in the OP. How is this problem related to a deflate compression method? I don't even have lib32z1 installed myself, and my installation works after applying this stackoverflow.com/a/44304075/2412477; I recommend anyone to try that before installing potentially unnecessary packages.
-
Stephan Henningsen about 7 years@Maxr1998 That's weird... I just upgraded to canary 4, applied the fix, and my Android Studio can successfully rebuild my app that has
dependencies { ... compile 'com.android.support:design:25.4.0' ... }
because it uses anandroid.support.design.widget.TextInputLayout
. I can also rebuild from shell, but remember that the fix must be applied here too, i.e.:LC_NUMERIC="en_US.UTF-8" ./gradlew clean assDebug
. -
Stephan Henningsen about 7 yearsI added a new section on fixing the shell as well.
-
Maxr1998 about 7 years@Stephan Henningsen not sure what I could have done wrong, though I'm actually using the SDK, tools and libs in version 26.X. I already fixed the error myself by just disabling aapt2 by setting
android.enableAapt2
(or similar) tofalse
in mygradle.properties
. Thanks a lot for the helpful answer anyway :) -
Etienne Lawlor about 7 yearsWhat about on mac OSX
-
Stephan Henningsen almost 7 years@toobsco42 Have you tried this stackoverflow.com/a/44430789/2412477 ? Note that I'm not on a Mac, so I don't know if this works for you.
-
Etienne Lawlor almost 7 yearsThere instructions are for Ubuntu. I don't know what steps you need to take on Mac osx
-
Stephan Henningsen almost 7 yearsHave you tried searching for
studio.sh
and modifying it? -
Stephan Henningsen almost 7 yearsTo all you Ubuntu users: I've added a new approach which I think could be the best. It Works On My Machine, but let me know what you think and if there're any errors.
-
ksugiarto almost 7 yearsI think this answer deserves its explanation.
-
lukassos almost 7 yearsthis answer helped but does not solve the issue just turns off the gradle module that caused it, if you need the aapt2 then definitely add
export LC_NUMERIC="en_US.UTF-8"
to your .bashrc which worked like charm for me -
devconsole almost 7 yearsSimpler solution for the .desktop launcher: let Studio do most of the work for you. Run Tools -> Create Desktop Entry, exit studio, open
~/.local/share/applications/jetbrains-studio.desktop
, addenv LC_NUMERIC="en_US.UTF-8"
to the beginning of the Exec line. -
Stephan Henningsen almost 7 years@devconsole Yep, that's the file I started with, but I like having things explicit so I renamed it and modified the name and icon. The reason for this is that I have both Android Studio 2 and 3 installed side-by-side, and if you make the .dekstop file from the IDEs, you cannot tell Android Studio 2 and 3 apart ... and one will probably overwrite the other's .desktop file =\
-
comodoro almost 7 yearsIt still occurs in my AS 3 beta2, and adding export LC_NUMERIC="en_US.UTF-8" to the beginning of the shell script sometimes does not work, probably a cache thing.
-
xdevs23 almost 7 yearsthe
LC_NUMERIC="en_US.UTF-8"
method works on jenkins too -
HendraWD over 6 yearswhat about MAC OS users?
-
HendraWD over 6 yearsHow to fix this on MacOS without disabling AAPT2?
-
Stephan Henningsen over 6 years@HendraWD I don't have a Macintosh, but I'd assume solution C should work on all unix-like systems. But it doesn't? What about setting
LC_ALL
instead? -
Mehbube Arman over 6 yearsI am developing in a windows environment, what change do I need for this?
-
XurajB almost 6 yearsandroid.enableAapt2=false is being deprecated and will be removed by the end of 2018.
-
Samuel Owino over 5 yearsThis might sound dumb but, how do I get to those settings on Android Studio 3.2.1?