Fixed
Status Update
Comments
uc...@google.com <uc...@google.com>
je...@google.com <je...@google.com>
to...@google.com <to...@google.com>
vi...@gmail.com <vi...@gmail.com> #2
There is a similar issue faced by me where the xml parsing is skipping the leading 0 from a value, please let me know if there is any update on this issue
xml.getAttributeValue(name, value);
The value here is received by removing the '0'
xml.getAttributeValue(name, value);
The value here is received by removing the '0'
sa...@gmail.com <sa...@gmail.com> #3
We too are facing same problem.
Seems to be a bug from AAPT2 XML Parser.
Surprised to see there was no response from Google/Android.
Hope Google will understand the severity of this issue and respond soon.
Seems to be a bug from AAPT2 XML Parser.
Surprised to see there was no response from Google/Android.
Hope Google will understand the severity of this issue and respond soon.
rt...@google.com <rt...@google.com> #4
AAPT2 is stripping the raw string value at compile time. We can add a flag to aapt2 called "--keep-raw-strings" which can be used to toggle off this stripping. This will increase your APK size if the coerced strings are often different from the raw string values.
vi...@gmail.com <vi...@gmail.com> #5
Could you please tell me in detail on how and where this flag --keep-raw-strings must be added in my gradle
rt...@google.com <rt...@google.com> #6
It is not possible at this moment. We will have to add a property to gradle's aaptOptions to pass the flag to aapt2.
vi...@gmail.com <vi...@gmail.com> #7
Could you please let me know by when and which version this will be available?
im...@google.com <im...@google.com> #8
@6 If you add the feature to 'aapt2 compile' I can take care of adding support for it on the gradle side. :)
rt...@google.com <rt...@google.com> #9
We actually need this flag in the final link. Could we create a parameter in aaptOptions that is passed to the final link instead of compile?
im...@google.com <im...@google.com> #10
@9 Yep, no problem at all. I'll add support for this once the flag is in.
rt...@google.com <rt...@google.com>
im...@google.com <im...@google.com> #11
Hi all,
The aapt2 prebuilts with the fix have landed in master. That means the fix should be available in AGP 3.4-beta1 or 3.5-alpha01. Once these versions are released you can use the --keep-raw-values flag by updating your build.gradle file:
android {
aaptOptions {
additionalParameters "--keep-raw-values"
}
}
Please take note that using this flag might increase the size of your APK.
The aapt2 prebuilts with the fix have landed in master. That means the fix should be available in AGP 3.4-beta1 or 3.5-alpha01. Once these versions are released you can use the --keep-raw-values flag by updating your build.gradle file:
android {
aaptOptions {
additionalParameters "--keep-raw-values"
}
}
Please take note that using this flag might increase the size of your APK.
[Deleted User] <[Deleted User]> #12
Using AS 3.5 which states that the issues was fixed (https://androidstudio.googleblog.com/2019/01/android-studio-35-canary-2-available.html ) with the option/flag above results in
unknown option '--keep-raw-values'.
Was the flag named different?
Edit: Whoops forgot to upgrade the AGP plugin in the project, too.
unknown option '--keep-raw-values'.
Was the flag named different?
Edit: Whoops forgot to upgrade the AGP plugin in the project, too.
im...@google.com <im...@google.com> #13
@12 Yes, the fix is in AAPT2 which matches the version of AGP - so you need to update the AGP version to 3.4+.
ge...@gmail.com <ge...@gmail.com> #14
Android Studio 4.0 have this similar behavior but with "+" plus character, it converts the string value to a float representation when it is parsed with XmlResourceParser.
For example
phone_code value is converted from "+376" to "376.0".
xml file in xml folder.
<countries>
<country
name="Andorra"
name_code="ad"
phone_code="+376" />
</countries>
Using this configuration fixes the issue, but is this considered a solution of this behavior?
This fix works only if it is configured in the build.gradle file of the application module, not working if it is configured in a project library in a multi module project.
android {
aaptOptions {
additionalParameters "--keep-raw-values"
}
}
For example
phone_code value is converted from "+376" to "376.0".
xml file in xml folder.
<countries>
<country
name="Andorra"
name_code="ad"
phone_code="+376" />
</countries>
Using this configuration fixes the issue, but is this considered a solution of this behavior?
This fix works only if it is configured in the build.gradle file of the application module, not working if it is configured in a project library in a multi module project.
android {
aaptOptions {
additionalParameters "--keep-raw-values"
}
}
ge...@outlook.com <ge...@outlook.com> #15
Comment has been deleted.
Description
Build #AI-181.5540.7.32.5014246, built on September 17, 2018
JRE: 1.8.0_152-release-1136-b06 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
OS: Microsoft Windows 10, version 10.0.17134 Build 17134
AAPT2 strips leading zeros from strings in XML files. For example, in the XML snippet below, AAPT2 will change James Bond's Agent Code from "007" to "7".
<Property Country="Great Britain" Agency="MI6">
<Item FullName="James Bond" AgentCode="007" />
<Item FullName="John Wolfgramm" AgentCode="0010" />
<Item FullName="Sam Johnston" AgentCode="0012" />
</Property>
So, after the app is built, when using XmlResourceParser the resulting string will come back as "7" and not "007" as expected.
This may be related to other oddities with XML and AAPT2 as I have seen in IssueTracker but I did not see any mention of this particular behavior.
Note: This question was asked on Stack Overflow back in December of '17 but there wasn't a resolution other than disabling AAPT2.