Is there any legitimate use for #+android:id? - android

After I upgraded my android tools to latest version to work on API21, trying to compile my project resulted in the following error:
update_languages_button_preference_layout.xml:2: note: did you mean to use #+id instead of #+android:id?
update_languages_button_preference_layout.xml:2: error: creating resource for external package android: id/layout.
update_languages_button_preference_layout.xml:2: error: Error: No resource found that matches the given name (at 'id' with value '#+android:id/layout').
The problem seems to be the line android:id="#+android:id/layout": replacing #+android:id by #+id was enough to be able to compile and run the project normally.
However, a rapid search through the whole codebase revealed a few other locations in the project where the construction android:id="#+android:id/... is used. These apparently didn't prevent the project from passing all tests, even if I can't assure they are all still in use.
Is there any legitimate use of android:id="#+android:id that would justify leaving those references in our xml files, and not replacing them all by #+id?
Why didn't they raise the same error as the first file did?

No, you should never use #+android:id in your app. The android namespace is reserved for the framework. This has never been safe for an app to use and will now generate a compile error.
For a little background, generating new IDs within the android namespace will put them in the unused space after the existing android namespace IDs. This will work fine until new IDs are added in the framework, at which point your internal ID will overlap with an actual framework ID and cause weird issues.
As for the other instances, those should be generating errors as well. It's possible that there is a bug in AAPT. Regardless, you should remove all instances of #+android from your resources.

Though my comment is very late. I faced same issue today, when updated my eclipse and tools. Changed #+android:id to #+id and it solved my issue.

Related

Problems porting Android App from VS2019 to VS2022

I am trying to upgrade an Android App to build under VS2022 and use the latest nuget packages. I am also trying to modify it so that it will work on phones, and not just tablets, so the display needs to scale properly. (This is an old project that started with VS2010, so there are many legacy problems.)
When I build it, I get the error message:
resource dimen/abc_action_bar_icon_vertical_padding_material not found.
The offending axml code is:
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
I know that this comes from the depreciation of R.dimen and that I should upgrade from the support library to AndroidX. I thought that I had done this.
My question is, How do I fix this? Should I add or delete packages? If I declare the value explicitly, what should I use? This happens in many files, so I want to make sure that it is fixed correctly.
I also get the message:
attribute menu not found
from the code:
app:menu="#menu/navigation_menu"
I assume this is a related problem.
Thanks,
Dan

Extreme case of "Error retrieving parent for item"

My Xamarin Android project doesn't compile anymore, with a couple error messages saying
Error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Widget.Design.TabLayout'
Other errors that were thrown previously were in the same style, but said
No resource found that matches the given name (at 'textColor' with value '#color/md_white_1000')
I am aware that this is a very common Xamarin bug that is normally fixed by cleaning and rebuilding or, in rare cases, by clearing all packages and package caches so that they are downloaded again. However, this did not fix my error. I also completely reinstalled Xamarin and Visual Studio, but the error persists. At this point, i don't really know what to do except completely reformat my Mac.
Are there any trouble shooting steps I missed? Is this a bug that is only present in some version so that I need to downgrade? Please help, as I haven't been able to compile my code now for two days.
The log is saying that the app could not find certain resources, like TabLayout and #color/md_white_1000.
Did you install the NuGet packages related to Android AppCompat libraries? In NuGet Package Manager, search for AppCompat libraries. For example:
https://www.nuget.org/packages/Xamarin.Android.Support.v7.AppCompat
Those are necessary to find AppCompat resources and themes.
I found the answer: Apparently the newest version of the Xamarin AppCompat Package is corrupt. I was able to compile again by manually copying the project from my colleague, who hadn't updated his packages (the packages are in our .gitignore). That solved the problem and also explains why clearing the package caches didn't work: Visual Studio simply re-downloaded the corrupt package.

No resource identifier found for attribute error when trying to compile xamarin android project

I'm using Xamarin to build an android application but I'm having this error every time I try to compile the application.
I've added my attrs.xml file to Resources/values, referenced my namespace like this:
xmlns:custom="http://schemas.android.com/apk/res/mynamespace" and added the property to the view.
What am I missing? I've seen several examples but all seem to be working ok.
The reference is all in lower letters to avoid errors. I've also tried removing the http://... part and changing the folder "res" for "lib". These changes make the app to compile but I'm unable then to get the value of the parameter.
Please, any help will be really appreciated.
Best regards.
I've found the answer to my problem. It seems that it's not necessary to keep the lower letters when referencing the package name so if your package name is "MyNamespace", instead of using:
xmlns:custom="http://schemas.android.com/apk/res/mynamespace
you have to use:
xmlns:custom="http://schemas.android.com/apk/res/MyNamespace
It works now!

Android Build in Eclipse not generating the right resource ids in R.java

I've got an Android project that includes references to a library project. The library project contains a resource (a renderscript bytecode package). The main project also has it's own resources, including a layout, which contains a field that looks like this:
<EditText android:id="#+id/edit_name" />
When I build my main project in ant, and I call findViewById(R.id.edit_name) at runtime, the call returns the EditText component I expect. But when I clean the projects and build them in Eclipse findViewById(R.id.edit_name) returns null.
Debugging the call shows that my component is present in the View at runtime, and actually has an id assigned, but it's not the same id as the value of R.id.edit_name (in this case, the id in R.java and the runtime value of R.id.edit_name == 0x7f070000, whereas the actual View that exists at runtime has mId == 0x7f080000)
With the ant build, R.java is created with R.id.edit_name === 0x7f080000 (which matches the id I observe when running the app.)
When I remove the library dependency in Eclipse, R.java contains R.id.edit_name == 0x7f070000, but so does the runtime, and everything works just fine.
I realize one good answer is to file a bug report with ADT/Eclipse, and use ant to build, but I'm developing the library and I want to be sure that it supports Eclipse users. So what I'm wondering is:
Are there known bugs in Eclipse that can cause this sort of thing? Are there known workarounds?
If not, what is the next debugging step?
Edit:
It turns out this is associated with using a Renderscript asset- when I remove the renderscript, the problem disappears (both projects use the 07 "type" tag in their ids.) I'd still totally love to hear about a workaround, but for now it looks like custom renderscripts in Eclipse built library projects is a non-starter. For reference, I'm using the latest and greatest Eclipse ADT (22.2.1)

Lint: “<key> is not translated in <language>” error

My Android app recently started throwing Lint errors when compiling. I'm getting <key> is not translated in <language>. It tells me If an application has more than one locale, then all the strings declared in one language should also be translated in all other languages.
Unlike some of the other similar questions on this subject, I'm currently only supporting one locale. Eclipse somehow has started thinking that I want to support multiple, and now throws errors when compiling. Yes, I can turn off lint checking when I'm building, or I could set this to a warning instead of a fatal error, but that's just hiding the problem, which is that Eclipse thinks there are multiple locales. How do I fix this?
Edit: I tracked down the source - I added a library project that had a values-da folder. Any way to get the rest of my app to ignore that folder, or do I have to just remove it?
The only thing that seemed to work for this (thanks #323go for the suggestions) was to delete the folder. Renaming the file may work for you, but I got intermittent "Invalid resource directory name" errors.

Categories

Resources