How to make aapt.exe resolve android styles in SDK Tools r12 - android

Since updating my SDK Tools to r12, an existing project (with zero code
changes) now fails during aapt generation with:
[INFO] C:\Dev\Android-sdk\platform-tools\aapt.exe [package, -m, -J,
C:\Source\android\Jumblee\target\generated-sources\r, -M,
C:\Source\android\Jumblee\target\filtered-manifest\AndroidManifest.xml,
-S,
C:\Source\android\Jumblee\target\generated-sources\combined-resources\res,
--auto-add-overlay, -I,
C:\Dev\Android-sdk\platforms\android-10\android.jar]
[INFO]
C:\Source\android\Jumblee\target\generated-sources\combined-resources\res\values\theme.xml:16:
error: Error retrieving parent for item: No resource found that
matches the given name '#android:style/WindowTitle.
The relevant lines from the resource file are:
<!-- Set the theme for the window title -->
<!-- NOTE: setting android:textAppearance to style defined above --
<style name="CustomWindowTitle" parent="#android:style/WindowTitle">
<item name="android:textAppearance">#style/CustomWindowTitleText</item>
</style>
Has anyone seem something similar?
Or better still know wtf is going on?

OK the issue I raised was http://code.google.com/p/android/issues/detail?id=18659
It turns out that #android:style/WindowTitle and a few other styles that people have been using are not published styles.
So the proper solution is to stop using those private styles. And the most appropriate way of doing that it is probably to copy the style in question to your own project and make it your own style.

Found Hot Fix, but yes it's just hot fix. Looking for better solution.

Related

AAPT: error: invalid resource type 'attr' for parent of style, after updating gradle

After upgrading from Gradle wrapper 4.4.1 to 6.1.1, along with going from Android build tools 2.3.0 to 4.0.0, builds all of a sudden fail with the following error:
res/values/treeview_styles.xml:3:5-6:13: AAPT: error: invalid resource type 'attr' for parent of style.
The resource file in question looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style parent="#android:attr/listViewStyle" name="treeViewListStyle">
<item name="android:background">#android:color/white</item>
<item name="android:divider">#drawable/divider</item>
</style>
</resources>
What is happening here, and how can I fix this?
Background information: The code comes from a tree list view control I am using in my app. I have simply copied the source tree into mine so that I could make some modifications.
The developer reference for android.R.attr mentions listViewStyle, stating it has been available since API 1, so I am wondering if it is a reference to that. On the other hand, my app uses appcompat-v7, and in my local SDK tree at extras/android/support/v7/appcompat/res/values/themes_base.xml I indeed found:
<style name="Base.Theme.AppCompat.CompactMenu" parent="">
<item name="android:itemTextAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:listViewStyle">#style/Widget.AppCompat.ListView.Menu</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.DropDownUp</item>
</style>
That looks as if android:listViewStyle is just an alias for #style/Widget.AppCompat.ListView.Menu. Indeed, using #style/Widget.AppCompat.ListView.Menu compiles and the UI looks OK at first glance.
Note that the toolchain upgrade included switching from AAPT to AAPT2. According to this question and its answers, AAPT2 is stricter about some things than its predecessor. In particular, parents of styles must be styles as well. That would at least explain the error message, we just need to hunt down the correct resource name.
ianhanniballake wrote:
The problem is parent="#android:attr/listViewStyle", so replacing that with an actual parent theme, and not something from an attribute, would indeed fix it. What theme are you using?
In addition i found that:
Behavior changes when using AAPT2:
Additionally, when declaring a element, its parent must also
be a style resource type. Otherwise, you get an error similar to the
following:
Error: (...) invalid resource type 'attr' for parent of style

Android resource compilation failed (values.xml:200: error: invalid color)

I just begin learning Android with Kotlin, and I'm learning to build sliding intro. During build of my android application, I'm getting following error:
things in my color.xml:
Android resource compilation failed
Output:D:\HCI_Retry\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:200: error: invalid color.
Command: C:\Users\Nasri\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\bdf42a08a9c0a8f46dee8cc9eb34b57b\aapt2-3.2.1-4818971-windows\aapt2.exe compile --legacy \
-o \
D:\HCI_Retry\app\build\intermediates\res\merged\debug \
D:\HCI_Retry\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #7
I have tried to find solution toward my problem, but non of the solution actually helped with my problem. I had tried to open the values.xml file in hope to find the problem, but still got no clue.
Any help would be appreciated
From the colors.xml image, it looks like the issue is the missing # in colorHighlight. Should be #B6B6B6 instead of just B6B6B6.
KaiRuCheng disappeared and did not post line 200 of colors.xml as was asked in comments, but for all who is looking for solution for similiar problem:
I was encountered the same and found that it was just quotes around color code. I had this:
<color name="paragraph">"#FF0074E1"</color>
But should have to have this:
<color name="paragraph">#FF0074E1</color>
Note quotes around color code. It seems to be obvious error but despite of it Android Studio rendered correctly all elements which are using that color, and this error appears during building only.
I am not sure if this was the reason for KaiRuCheng's problem, as we can't see line 200 of his/her colors.xml, but this definetly was a reason for my problem which looked exactly same.
Similar answer: for me, I had typed #color/something instead of #color/something ... Android Studio would not underline it and the difference was so small, it took me 15 minutes to find the problem.
I also encountered with such problem when upgrading to Gradle 3.3.2. In my case, it was using Cyrillic instead Latin
<color name="default_button_press">#cc3b3b3b</color>
cc was Cyrillic and Android Studio didn't underline on old Gradle version.

Error: style attribute '#android:attr/windowExitAnimation' not found

I recently upgraded to the gradle-3.0.0-alpha8 after which some styles are not resolved at compile time.
Develop envirment:
IDE: Android studio 3.0 Bate3
Gradle build tools : 'com.android.tools.build:gradle:3.0.0-beta3'
Gradle :gradle-4.1-all.zip
Error info:
Error:(94, 5) style attribute '#android:attr/windowExitAnimation' not found
Error:(94, 5) style attribute '#android:attr/windowEnterAnimation' not found
Setting android.enableAapt2=false in gradle.properties file can solve this isuue.
But, Instant App need android.enableAapt2=true. What would i do?
All the problem was solved already.
Cause of the problem:
There are two modules, A_module, B_module.
B_module has a style:
<style name="my_style”>
<item
name="#android:windowEnterAnimation">#anim/anim_toast_show</item>
<item
name="#android:windowExitAnimation">#anim/anim_toast_hide</item>
</style>
If B_module compile(':A_module')
Build or Clean, report a error location in A_module->Res->values->styles:
Error:(94, 5) style attribute '#android:attr/windowExitAnimation' not found
Error:(94, 5) style attribute '#android:attr/windowEnterAnimation' not found
Solution:
Removing the "#" at the start of the item name.
<item name="#android:windowEnterAnimation">#anim/anim_toast_show</item>
<item name="#android:windowExitAnimation">#anim/anim_toast_hide</item>
to:
<item name="android:windowEnterAnimation">#anim/anim_toast_show</item>
<item name="android:windowExitAnimation">#anim/anim_toast_hide</item>
Setting android.enableAapt2=false in the gradle.properties file fixes this issue. See the Stack Overflow question I linked.
It will help you!
Removing a custom attribute
I got a similar error when I deleted an attribute for a custom view. The reason the error came up was that I still had xml references to it in my project.
Pressing Ctrl + Shift + F to search the entire project for the offending attribute and then removing all references to it solved the problem.

System did not generate an Id for my new xml layout and show me same errors

I have 2 problem that I think both of them is for one reason:
When I try to add a new XML layout; that XML fail add successfully but in "Console" show me it:
[2014-05-04 18:41:11 - Example] W/ResourceType( 5804): ResXMLTree_node size 0 is smaller than header size 0x14.
[2014-05-04 18:41:11 - Example] D:\Android\Workspace\Example\res\menu\main.xml:4: error: Error: Resource id cannot be an empty string (at 'actionLayout' with value '#android:layout/').
and I can get resource to it in classes.
In "problem" tab:
Errors: Unparsed aapt error(s)! Check the console for output.
Location: line 1
Type: Android ADT Problem
and I cant solve it
Please same one help me ...
I sorted this out. So for anyone else still on the learning curve with me, the solultion is as noted in my comment. In addition -
aapt = Android Asset Packaging Tool From the Developers Guide - "The Android Asset Packaging Tool (aapt) takes your application resource files, such as the AndroidManifest.xml file and the XML files for your Activities, and compiles them."
The solution for me was simply to delete the error on the 'Problem' window (right click | delete). Then, force a rebuild by rerunning the app. Any remaining problems will now show up and be logged so you can track them down.
Hope this is helpful to others.

Segmentation fault with aapt

Trying to build and Android project using Maven, we are not able to compile it with google play services apklib with it.
I've tried to remove all the languages from the apklib, just keeping the default one, and it seems to be able to execute aapt with no problems.
Does anybody run into this problem? I've tried to do what Jake Wharton says in this website: https://github.com/JakeWharton/gms-mvn-install , but the Segmentation fault still happening.
Ideas?
Thank you for your time.
aapt: warning: string 'error_generic_text_toast' has no default translation in /Users/fjfernandez/Development/android-messenger/app/target/unpack/apklibs/com.google.android.gms_google-play-services_apklib_5/res; found: ca_ES cs de en eu_ES fr gl_ES it nl pt pt_PT sk
Segmentation fault: 11
The problem we had in code was in style. You cannot use #+id to make reference to any view ( I guess you should not reference any kind of view in your styles, but anyway).
No #+id in your styles.
Maybe you already solved this problem, but I find out if I don't define in Manifest package like "package=some.app.package" it gave me the same error like you had.
I had a menu file with unresolved #string reference. I copied the aapt command from the Eclipse Console tab and ran it in a standalone terminal window. I figured out the offending file from the aapt log.
(new resource id main from /home/paller/workspaces/android_dev/xxxxxx/res/menu/main.xml)
Segmentation fault (core dumped)
It does not look nice that aapt just crashes if it does not like something in its input files.
I just found out that when strings.xml contains %blabla%, aapt segfaults. I have created an issue here: https://code.google.com/p/android/issues/detail?id=68667

Categories

Resources