So I updated my Android Studio to v3.2. When I tried compiling the project, build fails.
Below is the error:
Android resource compilation failed
Output: C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:900: error: <item> inner element must either be a resource reference or empty.
Command: C:\Users\Ashish\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\7f1fbe9171e916e5044000cd76b749c8\aapt2-3.2.0-4818971-windows\aapt2.exe compile --legacy \
-o \
C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\res\merged\debug \
C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Daemon: AAPT2 aapt2-3.2.0-4818971-windows Daemon #0
Please do tell if there is any more information required. Any help will be appreciated.
I was facing this issue today after updating gradle from 3.1.4 to 3.2.0. I don't know why, but the build started to throw that exception. i deleted the build folder, and deleted the gradle caches folder but nothing worked, so i looked at the merged values.xml and turns out that my ids.xml was defining a wrong id that was being merged to the values.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="downloading_package" type="id">Baixando pacote de sincronização</item>
</resources>
And apparently this was working before the update... for my case i deleted the ids.xml file (it was useless in the project)
I wish i could know why before the update everything was working
the <item> in values.xml at line 900 ...might be of resource-type id.
the correct syntax would be (just as the error message tells):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="id_name" />
</resources>
see the documentation.
For me I had the layout width and layout height in the layout view and the LinearLayout view for databinding. This threw a duplicate error.
I fixed this by removing the layout_width and layout_height attributes in <layout>.
I'm just finishing this issue a few minutes ago, try to modify or delete id.xml, if you think you don't have it, try to find in another module in your app. I change my value resource from <item name="header_view" type="id">header_view</item> to <item name="header_view" type="id"/> and it worked for me.
just change your attr name which is present in resource -> values -> attr
<attr name="fontFamilys">
<enum name="roboto" value="0" />
<enum name="roboto_condensed" value="1" />
<enum name="roboto_slab" value="2" />
</attr>
for example if you are getting error related to fontFamily just change the the name build the application error will not come
i also meet the problem,you just need to find where the values in,and update it from <item type="id" name="id_name" >id_name</item> to <item type="id" name="id_name" />,now it's ok.
I got that problem when I'd quotation within <string> tag
<string name="vj_dialogue">I'm waiting</string>
when I escaped it with backslash '' . The problem was gone
<string name="vj_dialogue">I\'m waiting</string>
This could also happen if you mistakenly happened to not escape some value (apostrophe with backslash or ampersand with & or something else I am not aware of) under res/values/strings.xml file
to bring it in context here is an example ->
incorrect :
<string name="update_now">Let's Update now</string>
correct :
<string name="update_now">Let\'s Update now</string>
in your build gradle(Project:name) do it like that
classpath 'com.android.tools.build:gradle:3.+'
then rebuild your project .. after that it will show message to update your gradle from 4.6 to 4.10
In my case
<?xml version="1.0" encoding="utf-8"?>
is repeated twice in the XML. Make sure it should be one per a file at the top of the XML.
This is what worked for me:
In my build.gradle file > dependencies, I was implementing a newer version of appcompat library
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:21.0.3'
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation 'androidx.appcompat:appcompat:1.0.2'}
After commenting //implementation 'androidx.appcompat:appcompat:1.0.2' It worked fine. I would suggest, even if it's a different library, Please check the version you are using.
In your xml file, you may forget to add /> to brace your attribute.
Related
I'm trying to use the Runtime Resource Overlay (RRO) mechanism to overlay an xml resource, which is using custom attributes and custom namespace. When building the overlay APK the aapt2 (link) throws an attribute not found error.
How do I make known the custom attribute from the main application to the overlay?
Is it even possible to use custom attributes in an overlay?
Details:
The overlay contains of two files:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.test.simpleappoverlay">
<overlay
android:targetPackage="de.test.simpleapp"
android:targetName="Test"/>
</manifest>
and the xml file res/xml/my_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<MyConfig xmlns:app="http://schemas.android.com/apk/res/de.test.simpleapp"
app:text="hello">
</MyConfig>
<!-- I also tried: xmlns:app="http://schemas.android.com/apk/res-auto" -->
The main application defines the attribute text in res/values/attrs.xml:
...
<declare-styleable name="MyConfig">
<attr name="text" format="string" />
</declare-styleable>
Furthermore it defines the overlayable tag in res/values/overlayable.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<overlayable name="Test">
<policy type="public">
<item type="xml" name="my_config"/>
</policy>
</overlayable>
</resources>
To build the overlay I do this:
aapt2 compile -v --dir app/src/main/res/ -o SimpleAppOverlay.flata
and
aapt2 link -v --no-resource-removal
-I ~/Library/Android/sdk/platforms/android-29/android.jar
--manifest app/src/main/AndroidManifest.xml
-o sao.apk SimpleAppOverlay.flata
Which leads to the following output:
note: including /Users/bernd/Library/Android/sdk/platforms/android-29/android.jar
aapt2 W 09-01 14:33:06 20083 694697 ApkAssets.cpp:138] resources.arsc in APK '/Users/bernd/Library/Android/sdk/platforms/android-29/android.jar' is
compressed
note: linking package 'de.test.simpleappoverlay' using package ID 7f note: merging archive SimpleAppOverlay.flata
note: merging 'xml/my_config' from compiled file app/src/main/res/xml/my_config.xml
note: enabling pre-O feature split ID rewriting AndroidManifest.xml:
note: writing to archive (keep_raw_values=false)
note: writing AndroidManifest.xml to archive
note: linking app/src/main/res/xml/my_config.xml (de.test.simpleappoverlay:xml/my_config)
app/src/main/res/xml/my_config.xml:2: error: attribute text (aka
de.test.simpleappoverlay:text) not found
error: failed linking file resources.
I had a similar problem to this where I was trying to overlay an app with custom attributes in Android 10 and have a solution. There are two changes that are needed:
Part 1
It looks like your app name is de.test.simpleapp so your my_config.xml file should look like:
<?xml version="1.0" encoding="utf-8"?>
<MyConfig xmlns:app="http://schemas.android.com/apk/prv/res/de.test.simpleapp"
app:text="hello">
</MyConfig>
The important piece is specifying the 'prv/res/app.packagename' so it uses the namespace of the base app for the private attributes. If you used 'apk/res-auto' that would not work as it resolves to the name of your app (which in this case is the overlay app de.test.simpleappoverlay) which does not contain the definition of the private attributes.
Part 2
Since you now have a dependency on the main app when linking, you have to include it in the link command with a -I simpleapp.apk (or whatever the APK name is of the base app). Right now you are just including android.jar in the aapt2 link step which only contains the 'android' namespace and attributes. Therefore, you now need to add your base app in the include step so it can link properly against its namespace and attributes.
Like some of the other answers said though, this problem goes away in Android 11, but if you're stuck on Android 10 like I am hopefully this helps.
I don't think including new ids is supported in the current implementation of the RROs (at least in Android Q).
Regarding your error, aapt uses the android.jar to generate the apk for your overlay. Since it cannot find your new attribute, it throws an error. For this to work I believe you would need to use a modified android.jar including your attribute. One way of doing this is by modifying the Android SDK in the AOSP and creating your own version that you would then use for the aapt command.
Some time ago I switched my AOSP environment from Android 10 to 11. Google made quite a few changes to the Overlay mechanism. To my big surprise these changes fixed the problems I had when trying to "overlay" custom attributes.
With the Android 10 environment I observed while debugging that the Android XML parser returns "null" when trying to read the mentioned attributes. With idmap I was able to confirm that the attributes were present in the overlay and the target app, and that they were properly mapped.
Also all the linker errors were gone.
This question already has answers here:
Android Studio shows wrong file contents
(10 answers)
Closed 3 years ago.
Once I create a new project I get an error
C:\Users\User\Desktop\4Find\app\src\main\res\values\colors.xml:9:18: Error: XML document structures must start and end within the same entity.
My colours.xml file at default looks as below;
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidLayouts">
<shared>
<config />
</shared>
</component>
<component name="AndroidLogFilters">
<option n
I faced this problem before. Instead of reinstall it, what i did was delete AndroidStudio file which located at C:\Users\YourUserName\.AndroidStudio3.2 (.AndroidStudio file name should depends on your android studio version). This will reset android studio to default setting.
Hope this could help you.
colors.xml should be look like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#17AC82</color>
<color name="colorPrimaryDark">#17AC82</color>
<color name="colorAccent">#17AC82</color>
...........
</resources>
Something went wrong. It's not how colors.xml should look like, it's even not valid XML.
You can edit colors.xml but in my experience project will have other issues in its resources.
Try to create new project one more time.
Delete Android Studio file which located at
C:\Users\YourUserName\.AndroidStudio(version)
So I updated my Android Studio to v3.2. When I tried compiling the project, build fails.
Below is the error:
Android resource compilation failed
Output: C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:900: error: <item> inner element must either be a resource reference or empty.
Command: C:\Users\Ashish\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\7f1fbe9171e916e5044000cd76b749c8\aapt2-3.2.0-4818971-windows\aapt2.exe compile --legacy \
-o \
C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\res\merged\debug \
C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Daemon: AAPT2 aapt2-3.2.0-4818971-windows Daemon #0
Please do tell if there is any more information required. Any help will be appreciated.
I was facing this issue today after updating gradle from 3.1.4 to 3.2.0. I don't know why, but the build started to throw that exception. i deleted the build folder, and deleted the gradle caches folder but nothing worked, so i looked at the merged values.xml and turns out that my ids.xml was defining a wrong id that was being merged to the values.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="downloading_package" type="id">Baixando pacote de sincronização</item>
</resources>
And apparently this was working before the update... for my case i deleted the ids.xml file (it was useless in the project)
I wish i could know why before the update everything was working
the <item> in values.xml at line 900 ...might be of resource-type id.
the correct syntax would be (just as the error message tells):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="id_name" />
</resources>
see the documentation.
For me I had the layout width and layout height in the layout view and the LinearLayout view for databinding. This threw a duplicate error.
I fixed this by removing the layout_width and layout_height attributes in <layout>.
I'm just finishing this issue a few minutes ago, try to modify or delete id.xml, if you think you don't have it, try to find in another module in your app. I change my value resource from <item name="header_view" type="id">header_view</item> to <item name="header_view" type="id"/> and it worked for me.
just change your attr name which is present in resource -> values -> attr
<attr name="fontFamilys">
<enum name="roboto" value="0" />
<enum name="roboto_condensed" value="1" />
<enum name="roboto_slab" value="2" />
</attr>
for example if you are getting error related to fontFamily just change the the name build the application error will not come
i also meet the problem,you just need to find where the values in,and update it from <item type="id" name="id_name" >id_name</item> to <item type="id" name="id_name" />,now it's ok.
I got that problem when I'd quotation within <string> tag
<string name="vj_dialogue">I'm waiting</string>
when I escaped it with backslash '' . The problem was gone
<string name="vj_dialogue">I\'m waiting</string>
This could also happen if you mistakenly happened to not escape some value (apostrophe with backslash or ampersand with & or something else I am not aware of) under res/values/strings.xml file
to bring it in context here is an example ->
incorrect :
<string name="update_now">Let's Update now</string>
correct :
<string name="update_now">Let\'s Update now</string>
in your build gradle(Project:name) do it like that
classpath 'com.android.tools.build:gradle:3.+'
then rebuild your project .. after that it will show message to update your gradle from 4.6 to 4.10
In my case
<?xml version="1.0" encoding="utf-8"?>
is repeated twice in the XML. Make sure it should be one per a file at the top of the XML.
This is what worked for me:
In my build.gradle file > dependencies, I was implementing a newer version of appcompat library
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:21.0.3'
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation 'androidx.appcompat:appcompat:1.0.2'}
After commenting //implementation 'androidx.appcompat:appcompat:1.0.2' It worked fine. I would suggest, even if it's a different library, Please check the version you are using.
In your xml file, you may forget to add /> to brace your attribute.
My understanding is that suppressing individual warnings can be done in XML by adding an ignore property, e.g.
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="SpUsage"
android:textSize="30dp"
This works fine when the text size is directly specified. But when I use a reference to a dimension, e.g.
android:textSize="#dimen/largeTextSize"
Lint produces a warning in spite of the ignore.
Let's assume that the given case is a justified exception, and that the guidance on generally preferring sp dimensions over dp for text is well understood and followed.
Because this is an exception I do not want to disable the warning globally. How can I do it locally?
You need to add the suppression on the dimen value resource:
<resources xmlns:tools="http://schemas.android.com/tools">
<dimen name="largeTextSize" tools:ignore="SpUsage">123dp</dimen>
</resources>
Only that approach helped me:
Specify lint checking preferences in the lint.xml file. Place it in the root directory of your Android project.
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="SpUsage" severity="ignore" />
</lint>
More about lint config look at: https://developer.android.com/studio/write/lint#config
I'm trying to set the android:versionName in my android manifest as a reference to string resource stored in external resource file.
Below is an excerpt from my AndroidManifest.xml:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toycorporation"
android:versionCode="#integer/version_code"
android:versionName="#string/version_name"
>
and the content of build.xml file located under res/values disrectory of my project:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item type="string" name="build_date">03/15/2012</item>
<item type="integer" name="version_code">315281</item>
<item type="string" name="version_name">3.15.28.1</item>
</resources>
Later I attempt to retrieve the version number to display it on the About screen of my application.
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),0);
Log.d("PackageInfo", "Version name: " + String.valueOf(packageInfo.versionName));
Problem description:
When I build the application and automatically install it on my HTC device everything works perfect. Version name gets passed by reference and on the About screen I get version name value logged in the logcat.
But when I attempt to build the application and launch it on the emulator I get null instead of the version name value.
I have already tried to build and install the app to emulator using Eclipse and IDEA.
So it seems the issue is not related to IDE.
UPDATE:
One additional thing appeared which doesn't work with such use of versionName and versionCode. Application can not be deployed to the Google Play. The following error appears:
The file is invalid: ERROR getting 'android:versionCode' attribute:
attribute is not an integer value
I think there is a mix of issues with this approach / how you are using it.
1.) if you can compile and upload the APK to the android market and the correct version number and name is used then you are able to use resource references for the android:versionCode="#integer/version_code" android:versionName="#string/version_name"
If you can't then you shouldn't be using rerences.
2.) If you are going to take this approach, why then try to retrieve them from the packageinfo over using getResources().getString(R.string.version_name)?
All in all I don't see much of an advantage of this approach beyond being able to swap out a resources file by a build box. In which case you may need to for the latter approach to populate your about screen.
You can set versionName in manifest as a reference to string resource, but not versionCode.
This should work. in dimensions.xml add the following.
<resources>
<item name="version_number" format="float" type="dimen">2.8</item>
<item name="version_code" format="integer" type="dimen">8</item>
</resources>
In your manifest add the following.
android:versionCode="#dimen/version_code"
android:versionName="#dimen/version_number"