I'm using two libraries in my projects: holoeverywhere and google maps v2. Everything works just fine except when I try to use the libraries custom xml-attributes.
Since ADT r17 we no longer have to use the package name to define the namespace, instead we use "http://schemas.android.com/apk/res-auto". res-auto is automatically substituted with the package name.
For example if you want to configure the initial state of a google map fragment in xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:uiCompass="true"
map:mapType= "normal"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="true"
map:uiZoomControls="true"
map:uiZoomGestures="true"/>
I keep getting an error: No resource identifier found for attribute 'map' in package ‘res-auto’
Same thing happens when I use xmlns:holo="http://schemas.android.com/apk/res-auto"
I cannot access the custom xml attributes of that namepsace!
Now I know you can create a map fragment programatically but I want to find a solution for this. What am I missing? Also i'm targeting apis 10-17!
Any help is appreciated. Thanks.
At least for Maps V2, you are probably running into this bug in the Eclipse tools.
Related
While I try to add wenchaojiang AndroidSwipeableCardStack library to my project. While I succeed to add this library but got an error in the following case.
In main Activity layout, I required adding the,
<com.wenchao.cardstack.CardStack
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:gravity="center"
android:padding="10dp"
/>
Also I need to add the following with this
app:card_enable_loop="false"
app:card_enable_rotation="true"
app:card_gravity="top"
app:card_margin="20dp"
app:card_stack_size="4"
I got error as Decleration not found or error: attribute 'business.contacts.cardwithlib:card_enable_loop' not found.
I try many solutions like,
Include card 'com.android.support:cardview-v7:27.1.1' , add auto-generating xmlns:app="http://schemas.android.com/apk/res-auto" and Open their project and work fine for me in that project
I noticed that you are no including the Android's CardView but what it looks like a 3rd party library.
com.wenchao.cardstack.CardStack
Is this intentional? If so, maybe this component doesn't extend the CardView element, those specific style attributes might not be available.
I am, at the moment, trying to make a google maps app using android studio.
Right now, everything is fine, except for one thing, when i go to the "Design" Tab, in the XML file i have this Redering message:
Rendering Problems A tag allows a layout file to
dynamically include different layouts at runtime. At layout editing
time the specific layout to be used is not known. You can choose which
layout you would like previewed while editing the layout...
And the main problem is that I cannot use any of the gui components in my layout, I searched about my problem and i understood that with this error, people couldn't see their map but they could put on textfields, widgets, layouts, etc.
But for me, my preview is completly frozen and i can't do any modification.
Picture of my android studio page.
As you can change the fragments dynamically with your code, android studio doesn't know which layout to show in design time. This is the reason of your error.
To specifically tell android which layout to show, add tools:layout="#layout/Your_layout_name" attribute to your fragment.
There is also a shortcut link below the error description which you have told. Just click on the link and android will add it for you and you will see the fragment in your layout with no rendering error messages.
For a detailed example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.insane.fragmenttest.MainActivity">
<fragment
android:id="#+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="#layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
Try using Designtime Layout Attributes. http://tools.android.com/tips/layout-designtime-attributes
These attributes guide Android Studio on how to render run-time attributes in the layout editor.
I think you should include tools:showIn="#layout/activity_maps" in your the <fragment> part of your google_maps_api.xml
Just use this design for the fragment. This solved my problem. Also, refer to this link
<fragment
android:id = "#+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
Yes I solved this easily..Simply ignore the message and click line that is showing below of the rendering messages.
Actually fragment contains layout inner and if its not include its showing warning that it must contains you can simply ignore this message below the warning then this rendering issue will be resolved.
I have seen custom xml with :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
and
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/com.package.custom"
whats the difference between these two separate names?
Is the latter only points to default location like your package?
Is the former points to the reference lib ?
thanks.
If we add a new custom view and its attributes inside our project, you add this at the beginning of your layout:
xmlns:custom="http://schemas.android.com/apk/res/your_main_app_package
If the new custom view is inside a library project linked to your project, you add this:
xmlns:custom="http://schemas.android.com/apk/res-auto
Note: This problem has been fixed in ADT revision 17+ . For any services or Activities, declare the namespace as follows:
xmlns:custom="http://schemas.android.com/apk/res-auto"
The suffix res-auto will be replaced at build time with the actual project package, so make sure you set up your attribute names to avoid collisions if at all possible.
After doing a lot of research, and not finding anything... quick question, does anybody has an idea why Android Studio is not taking the Map tag? The code below is a fragment of the maps sample in the SDK. Already added google play services lib and support, but nothing.
It's showing the error
Unexpected namespace prefix "map" found for tag fragment.
Thanks a lot in advance!
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraZoom="10" />
I had the same problem once I've been moving the map fragment into FrameLayout (so I could add a button on top of the map).
I don't know what I've really done as I'm a noob in Android apps and XML, but it looks that I found the solution :-)
I tried to make the trick including the fragment from a separate file (using 'include' directive) and once I put the bare map fragment without any namespace definitions it proposed me 2 options:
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/tools"
I realized that maybe the 2nd one will work in the original file (although in original file Android Studio is not proposing it, but only the 1st one instead).
Conclusion:
Just change this line:
xmlns:map="http://schemas.android.com/apk/res-auto"
with this:
xmlns:map="http://schemas.android.com/tools"
AS I MENTIONED - I'M A NOOB AND MAYBE MY SOLUTION GOT SOME SIDE EFFECTS SO PLEASE LET ME KNOW IF SO (although everything seemed to be working fine by so far...).
That's my working map layout with a button on the top and no errors:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/tools"
tools:context="com.maverickrider.myapp.inviteActivity.MapsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/purpura_E51B4A">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraTargetLat="51.513259"
map:cameraTargetLng="-0.129147"
map:cameraTilt="30"
map:cameraZoom="13"
/>
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="cokolwiek"
android:text="Baton z dupy"
android:layout_alignParentBottom="true"
/>
</FrameLayout >
I had this problem as well. I did Project/Clean and the error went away and it works fine now. This assumes that the map namespace is properly defined above where it's being used.
I'm running 0.5.8 and the XML viewer is underlining the attrs with map: - however the app is building fine. YMMMV.
I'm trying to learn android, and having followed the instructions on how to use the Google Maps API V.2 I now got it working.
However, the instructions on how to configure the initial state of the maps, found at developers.google.com, suggests a namespace defined in the xml-file, in this case "map".
The xml-code below gives med the error "Unexpected namespace prefix "map"". Trying to define the xmlns:map inside the fragment tag gave the same error but with "xmlns".
I'm obviously missing some fundamental xml-knowledge here, can someone help me out?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto" <!-- Definition -->
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"/> <!-- PROBLEM -->
</RelativeLayout>
I had this problem as well. I did Project/Clean and the error went away and it works fine now.
You have to do two things:
First:
https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw
Add the dependency to Google Play Services into your project
Project -> Properties -> Android -> Library, Add -> google-play-services_lib
Second:
https://developers.google.com/maps/documentation/android/intro
Select Project > Properties, select Java Build Path, and navigate to Libraries.
Select Add External Jars, include the following jar files, and click OK:
<android-sdk-folder>/extras/android/compatibility/v4/android-support-v4.jar
Now my project shows no errors anymore :)
I have the same problem today. I upgraded the SDK last night and did not see this problem before. I had the Android Map V2 sample demo project loaded too and today the "multimap_demo.xml" file is showing the "Unexpected namespace prefix "map" found for tag fragment" error. I applied the xml include suggested and it is working again. Would give it a +1 but got no cred.
UPDATE:
I forgot about this problem and reworked my code today and removed the include. Of course the error came back. I found this and added it to the layout in the fragment stanza:
tools:ignore="MissingPrefix"
It seems to at least mask the problem.
Update: This bug apparently happens due to a bug in Android Lint Tool. Refer issue https://code.google.com/p/gmaps-api-issues/issues/detail?id=5002
There is another workaround that lets you continue to set everything up in layout files instead of in the Java code. Since the error only seems to happen when the SupportMapFragment is a child of a ViewGroup in the layout file, one can extract the <fragment> element into its own layout file and then just include it in the desired larger layout.
For example, given that you are trying to do this:
my_awesome_layout.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"/>
</RelativeLayout>
You could instead break it up like so:
include_map_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://scheams.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"/>
my_awesome_layout.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/include_map_fragment" />
</RelativeLayout>
Well, I know, this isn't really a solution for the name space problem, maybe this might help.
Since I don't know any XML solution, I did it programmatically:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setTrafficEnabled(true);
setupMapView();
private void setupMapView(){
UiSettings settings = mMap.getUiSettings();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition(new LatLng(50.0, 10.5),
13.5f, 30f, 112.5f))); // zoom, tilt, bearing
mMap.setTrafficEnabled(true);
settings.setAllGesturesEnabled(true);
settings.setCompassEnabled(true);
settings.setMyLocationButtonEnabled(true);
settings.setRotateGesturesEnabled(true);
settings.setScrollGesturesEnabled(true);
settings.setTiltGesturesEnabled(true);
settings.setZoomControlsEnabled(true);
settings.setZoomGesturesEnabled(true);
}
So the Google Map is initialized default but gets its parameters directly after that from the code.
I've got exactly the same problem. The provided example
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"
map:cameraTargetLat="-33.796923"
map:cameraTargetLng="150.922433"
map:cameraTilt="30"
map:cameraZoom="13"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="true"
map:uiScrollGestures="false"
map:uiTiltGestures="true"
map:uiZoomControls="false"
map:uiZoomGestures="true"/>
works fine, but if you try to add it into a parent element it refuses to accept the xmlns. If you move the xmlns declaration to the top element it still refuses to accept the map prefix in the fragment:
Unexpected namespace prefix "map" found for tag fragment
Now if you extend SupportMapFragment and use a custom view such as this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<com.google.android.gms.maps.MapView
android:id="#+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraBearing="0"
map:cameraTargetLat="54.25"
map:cameraTargetLng="-4.56"
map:cameraTilt="30"
map:cameraZoom="5.6"
map:mapType="normal"
map:uiCompass="true"
map:uiRotateGestures="true"
map:uiScrollGestures="true"
map:uiTiltGestures="true"
map:uiZoomControls="false"
map:uiZoomGestures="true">
</com.google.android.gms.maps.MapView>
</LinearLayout>
...then it doesn't complain and the resultant map is correct. For me that raises further problems however as there are no decent examples of how to do this subclassing, you have to do more than override onCreateView and when I try to do anything to the map subsequently I get the following:
java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.
...even if I wait 30 seconds after the map has appeared.(only first loading)
I don't think you can put XML comments inside a tag like you are doing with <!-- Definition -->. If you remove that does the problem still occur?
Obviously this is just a mis-lead Lint check error. You can remove it when, in Eclipse's Problem view, you right-click the line with the error, select the Quick fix option and select e.g. Ignore Check for project.
The error goes away, the project builds and the app runs perfectly well.
In my case a big miss, I forget to add in the gradle file my google map dependency:
compile 'com.google.android.gms:play-services-maps:11.2.0'