A xmlns:android, how does that actually work? - android

Consider the following perfectly well formed layout file on android:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, PurpleActivity"/>
</LinearLayout>
I looked at this and got curious about that ULR: http://schemas.android.com/apk/res/android. So, I tried to enter it into my web browser's address bar and also tried to fetch it via CURL, but both methods showed that it doesn't actually exist. I looked for something akin to an apk/res/android directory in the android-sdk folder on my local machine, but that searched turned up nothing as well. So, I figured since this resource didn't actually exist, maybe that I could change the xmlns:android line to whatever I wanted. I went ahead and changed it to
http://schemas.android.com/apk/res/androidASDFASDFASDFASDFLKJSDFLEIE
and then tried to recompile my project. I got this result:
-resource-src:
[echo] Generating R.java / Manifest.java from the resources...
[aapt] (skipping hidden file '/Users/rutski/Desktop/purple/res/layout/.#main.xml')
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'orientation' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'layout_width' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:2: error: No resource identifier found for attribute 'layout_height' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'layout_width' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'layout_height' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
[aapt] /Users/rutski/Desktop/purple/res/layout/main.xml:7: error: No resource identifier found for attribute 'text' in package 'androidASDFASDFASDFASDFLKJSDFLEIE'
This leaves me confused. If the resource doesn't exist anyway, then what does it matter if I change the xmlns:android value to some other nonexistent resource? And if it does exist, then where is it?

xmlns:android="http://schemas.android.com/apk/res/android" declares an XML namespace prefix. xmlns indicates it's about a namespace declaration. android is the prefix. http://schemas.android.com/apk/res/android is a URI - a string that uniquely identifies which namespace is referred to. The URI can be something abstract (as in this case); it is not necessarily a URL that physically locates something.
In general, you are free to choose the actual prefix. You can most likely replace android with something else and it will still work.
So what that attribute actually means is "We need to work with nodes from the namespace http://schemas.android.com/apk/res/android here, and in this file, we're going to refer to that namespace as android.
If, in several files, you define different namespace prefixes using the same URI, all those files will be referring to the same namespace - because the URI is the same. The prefix can be seen a a shorthand notation for referring to the actual namespace. The prefix can only be used inside the file that defines it.

It's not a resource, it's just a URI. Usually, processes that work with XML files expect a specific XML namespace. When you use your namespace, it's as if you renamed the attributes to something else. And so the tools that work with them don't recognize them anymore.

Related

cant add the banner Ads of the airpush new SDK

i am trying to add this in my main.xml
<com.jrlnv.qmais91534.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="#+id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:banner_type="inappad"
ap:placementType="interstitial"
ap:test_mode="false"
ap:canShowMR="false"
/>
this is the banner ads from the new airpush SDK
but i got this errors
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'canShowMR' in package 'com.MKA'
- error: No resource identifier found for attribute 'placementType' in package 'com.MKA'
- error: No resource identifier found for attribute 'banner_type' in package 'com.MKA'
- error: No resource identifier found for attribute 'animation' in package 'com.MKA'
- error: No resource identifier found for attribute 'test_mode' in package 'com.MKA'
any help
thank you
You also need to place the mraid_attrs.xml file into your app's res > values folder. This file is included within the SDK download.

air push adview error

I am embeding air push ads in my android app. I added adview in layout.xml file. It has errors that are
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'canShowMR' in package 'com.GUI.traficsing'
- error: No resource identifier found for attribute 'banner_type' in package 'com.GUI.traficsing'
- error: No resource identifier found for attribute 'placementType' in package 'com.GUI.traficsing'
- error: No resource identifier found for attribute 'refresh_time' in package 'com.GUI.traficsing'
- error: No resource identifier found for attribute 'animation' in package 'com.GUI.traficsing'
- error: No resource identifier found for attribute 'test_mode' in package 'com.GUI.traficsing'
Thank you
You need to place the mraid_attrs.xml file into your app's res > values folder. This file is included within the SDK download.
It solved me the same problem.
Ref: http://manage.airpush.com/docs/index.php?title=Android_SDK_6.0_Documentation

Custom XML error with Android Build Tools (0.4.2) -- No resource identifier found for attribute 'gapWidth' in package 'xxx.xxxx.'

Updated to the latest Android Build tools (0.4.2) and ran into the following when attempting to assemble:
/AndroidApp/App/build/res/all/flavor/debug/layout/fragment.xml:84:
error: No resource identifier found for attribute 'gapWidth' in package 'com.viewpagerindicator'
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/build/res/com.viewpagerindicator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
Since flavors may use a different packagename, instead of specifying the package name in the custom namespace, use: 'http://schemas.android.com/apk/res-auto'.
Update your custom XML link paths to use build instead of apk.
Was, in the fragment.xml file
xmlns:app="http://schemas.android.com/apk/res/com.viewpagerindicator"
Now, to this:
xmlns:app="http://schemas.android.com/build/res/com.viewpagerindicator"

No resource found that matches the given name in Manifest

I'm getting this error when trying to build the application. The xml editor did not highlight both error as missing. As the file/string are already there.
android-apt-compiler: [XXX]
D:\private\xxx\android\XXX\src\AndroidManifest.xml:35: error: Error:
No resource found that matches the given name (at 'icon' with value
'#drawable/ic_launcher').
android-apt-compiler: [XXX]
D:\private\xxx\android\XXX\src\AndroidManifest.xml:233: error: Error:
No resource found that matches the given name (at 'value' with value
'#string/FacebookAppID').
The project structure is like this:
ProjectFolder
|-external_lib
|-src
|-src (actual source)
|-res
|-...
I can confirm that both file is already in the project. As I use IntelliJ, I could just Ctrl + click then it open those files for me. However, I'm still getting this error.
I checked with both Google and SO. Most of the issues were about not having the files or storing in different folders. Which I can ensure that it is in the right place alongside hundred other files and strings.
Another issue is about % sign in strings.xml. I tried searching for "%" and nothing is found in the file.
Shutting down IDE and reopen it doesn't help, nor rebuilding the project. How could I get the app to build?
Look for any error message during the resource compilation.
Sometimes, if you have resource filenames containing illegal characters (such as underscores or uppercase letters), the whole process fails almost silently, and the IDE can't find any resources anymore.
I'm not sure that it's what is happening in your case, but I did eventually encounter such issues...

GridLayout compatibility

I am working on an application for which I need to make GridLayout compatible. So I am following the steps given in this link. I have downloaded zip folder and also have made it library. Everything is working fine till implementation. When I am trying to change main.xml as described as in the given link , I am getting . The error code is as follow.
<com.gridlayout.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gridlayout="http://schemas.android.com/apk/res/com.CompatGrid.MakeCompatible"
android:layout_width="match_parent"
android:layout_height="match_parent"
gridlayout:alignmentMode="alignBounds"
gridlayout:columnCount="4"
gridlayout:columnOrderPreserved="false"
gridlayout:useDefaultMargins="true" >
My package name is "com.CompatGrid" and my Activity is "MakeCompatible". Error is in 3rd , 4th, 5th and 6th line.
Errors are something like that.
error:No resource identifier found for attribute 'alignmentMode' in package 'MakeCompatible'.
error:No resource identifier found for attribute 'columnCount' in package 'MakeCompatible'.
error:No resource identifier found for attribute 'columnOrderPreserved' in package 'MakeCompatible'.
error:No resource identifier found for attribute 'useDefaultMargins' in package 'MakeCompatible'.
I have done as the instructions are given.
After reading again and again I found out my error. It was in 2nd line.
xmlns:gridlayout="http://schemas.android.com/apk/res/com.CompatGrid.MakeCompatible"
I edit it to
xmlns:gridlayout="http://schemas.android.com/apk/res/com.CompatGrid"
My mistake was I had to use the package name , not the main Activity Class name in the main.xml.

Categories

Resources