I have been developing a simple app for load a map view. I have followed the API. https://developers.google.com/maps/documentation/android/start#add_a_map
BUT
after the execution app goes force close and a LOGCAT ERROR
The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0.
this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newgmaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA5QozHkGwJP_9iJi7jtBV938T1wws02gA" />
<activity
android:name="com.example.newgmaps.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
this is my main xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
and this is main activity
package com.example.newgmaps;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Do these 2 steps and let me know please
1st update your Google play services as show here
2nd try out this new manifest file that i have created for you
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newgmaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="11" />
<permission
android:name="com.example.newgmaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="icom.example.newgmaps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="4030500" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA5QozHkGwJP_9iJi7jtBV938T1wws02gA" />
<activity
android:name="com.example.newgmaps.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
let me know if you solved this problem also
Thank you
Use the previous version of Google Play Services libproject for now. It can be downloaded from here: https://dl-ssl.google.com/android/repository/google_play_services_3225130_r10.zip
Worked for me.
You can then update this later when Google makes the latest version available to everyone but something tells me it will be a while before this change propagates to all the devices out there.
I have the same problem when running the app on my 2012 N7 running 4.3.
I don't think the actual released version of Play Services matches the SDK version in version.xml:
google_play_services_version 4030500
So it's either a case of waiting for a Play Services update on Play Store, or possibly try changing the version.xml in google-play-services_lib.
If you start the Android SDK manager you should see a "Google play services for Froyo" module. Install and use this instead of the "new" version. This worked for me.
Google must update Google play services to version 4.xxx
I added this below xml code in "AndroidManifest.xml"
<Application
...
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
...
</Application>
The crash error was disappeared.
But when I call...
int iErrorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
"iErrorCode" is 2. 2 means like this
public static final int SERVICE_VERSION_UPDATE_REQUIRED
The installed version of Google Play services is out of date. The calling activity should pass this error code to getErrorDialog(int, Activity, int) to get a localized error dialog that will resolve the error when shown.
Constant Value: 2 (0x00000002)
Details...
And also LogCat said...
W/GooglePlayServicesUtil(4728): Google Play services out of date. Requires 4030500 but found 3266136
Where is version code "4030500"??
[SDK]\extras\google\google_play_services\libproject\google-play-services_lib\res\values
You can see "version.xml". Open it!
<?xml version="1.0" encoding="utf-8"?> <resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
Peekaboo~~! :)
This is why we got this errorCode(2) when update new SDK and use new "google-play-services-lib".
Okay! Got it! Let's check my Google Play Version on my device.
The version on my phone is "4.4.21" There is no problem I think.
What is this "3266136"? Where were this from? I cannot understand this.
If I figure this out, I will update this long answer.
Good luck! Everybody! :)
Updated 1:
I downloaded apk 4.4.22 and installed on my phone. But, LogCat still show me "3266136".
This is really odd thing. I think Google-Team have to fix it ASAP!!
4.4.22 Download here...
Updated 2:
After all, I decided to down-grade "google-play-services_lib" and "android-support-v4.jar" to previous version. I will be wait for them. :)
try to add this meta-data tag in the application tag in the Manifest :
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
Related
I had my existing android project going unmanageable due to unnecessary research codes, so I decided to create a new project with only necessary code that's required for the app. I uploaded the same on play store's beta environment. As the app got updated on my phone, the already existing app icon on home screen got removed. Did I make any mistake in the code development?
Please help
EDIT: Added Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abc"
android:installLocation="preferExternal"
android:versionCode="52"
android:versionName="5.0.004" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name="com.example.abc.Appname"
android:allowBackup="true"
android:icon="#drawable/launcher"
android:label="#string/app_name"
android:theme="#style/Theme.CustomTheme" >
<activity
android:name="com.example.abc.SplashScreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_app_name"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</manifest>
Reverted back the application name to old file name (java class) and the same in manifest file. The launcher icon was created while installing via Google play store's beta environment.
Still unsure why the application name and java class names had an impact on the launcher icons. Any idea?
I'm new here and also new in programming.
I'm making map, I have followed a lot of tutorials, all of them very simillar but I don't know why my app doesn't work. The app doesn't crash, but when I open the map appears the app title and a white screen where the map should appear. Do you know why is this happening?
Here are my app manifest, the activity:main.xml and the mainactivity.java, maybe here's the error that I can't find.
Also if helps logcat says me: Error opening trace file: No such file or directory (2)
APP MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tdr.mapa1"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.tdr.mapa1.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="permission_name"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.tdr.mapa1.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"
android:required="false"/>
<activity
android:name="com.tdr.mapa1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<API_KEY>"/>
</application>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</manifest>
MAIN ACTIVITY
<RelativeLayout 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=".MainActivity" >
</RelativeLayout>
MAINACTIVITY.JAVA
package com.tdr.mapa1;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Hope you can help me.
See here,just change the api key with your key in manifest file and follow these steps:
and make sure that generate api key with package name which is mentioned in android manifest file and your google_play_services_lib project should be present in your project's work space only.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geeklabs.map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="replace with your API key"/>
</application>
</manifest>
MainActivity.java:
package com.geeklabs.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
And make sure following steps done correct or not:
Steps:
* to ensure that device has Google Play services APK
* to install Google Play Service rev. more than 2
to create project at https://code.google.com/apis/console/
to enable "Google Maps Android API v2"
to register of SHA1 in project (NOW, YOU NEED WRITE SHA1;your.app.package.name) at APIs console and get API KEY
to copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project
to add next line to the YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
to add next lines to the YOUR_PROJECT/proguard-project.txt
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Okay, now you ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
After got this let me know.
First your error:
Error opening trace file: No such file or directory (2)
doesn't mean anything and you should node pay any attention to it.
Second, both meta-data tags should be inside of the application scope, like so:
...
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<API_KEY>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Lastly, you are not actually creating any map object in your activity layout file, what you have there is an empty RelativeLayout and hence the empty white screen. What you need is to add an MapFragment in there or SupportMapFramgnet depending on your target api. (In your case it would be MapFragment.)
Like so:
<RelativeLayout 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=".MainActivity" >
<fragment
android:name="com.google.android.gms.maps.MapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
You can get more detailed information from this blog post I wrote on this topic:
Google Maps API V2 Guide
I had a working Google maps API v2 for Android example application that worked perfectly until I initialized a git repository in it's directory.
I have since then erased the entire project, all references to it in the Google cloud control, and started a new project.
The problem I'm facing now is an authentication issue:
11-07 10:44:05.445: E/Google Maps Android API(3640): Ensure that the following correspond to what is in the API Console: Package Name: [package name], API Key: [key], Certificate Fingerprint: [fingerprint]
I already tried with no avail:
1. Triple check API key and correct
2. Erase the entire project, disable Google maps API v2 for Android, enable it again and recreate the project
3. Add permissions for MAPS_RECEIVE
4. Cleaning, removing, and re-installing the release package
Really stumped by this one...
Here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.mypackage"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.mycompany.mypackage.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.mycompany.mypackage.permission.MAPS_RECEIVE" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="[My Key]" />
<activity
android:name="com.mycompany.canipark.MapExample"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is the code:
package com.mycompany.mypackage;
import com.mycompany.mypackage.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MapExample extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gmaps);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gmaps, menu);
return true;
}
}
And the layout:
<?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:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:mapType="normal" />
And the Google cloud console:
http://i.stack.imgur.com/hSx9N.jpg
http://i.stack.imgur.com/8sNbm.jpg
ID of your package is com.mycompany.canipark, but in console com.mycompany
Also, try to write
<uses-library android:name="com.google.android.maps"/>
In AndroidManifest.xml in <application> section
I really don't understand this..
I waited two days, and suddenly everything's working again. I didn't change a single line of code.
Wish Google will add a meaningful error other than Authorization failure when it does...
Thanks guys for your help!
Yesterday API 19 came out so I upgraded SDK and other (including Google Play Services)
now this method:
private boolean isGooglePlayInstalled(){
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(status == ConnectionResult.SUCCESS){
return true;
}else{
((Dialog)GooglePlayServicesUtil.getErrorDialog(status, this,10)).show();
}
return false;
}
Throws at line int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
How to fix that? I didnt have element "com.google.android.gms.version" in manifest before and it worked.
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sabatsoft.driveit"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.sabatsoft.driveit.activity.Start"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- other activities -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza*********************************1MZI" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
This worked for me:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Place this at the end of your manifest, after your Map API key meta-data tag. Since you check for GPlayServices availability in your onCreate method, such as:
// Check status of Google Play Services
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// Check Google Play Service Available
try {
if (status != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
}
} catch (Exception e) {
Log.e("Error: GooglePlayServiceUtil: ", "" + e);
}
...then once you click the dialog box to update GPlayServices, you will be brought to the GPlayStore. Usually, I uninstall from the GPlayStore menu, then the option to update will be available. It should work after that.
Package contents comparison
The "google_play_services_froyo" lib project contains these com.google.android.gms packages:
appstate
auth
common
dynamic
games
gcm
internal
location
maps
panorama
plus
On the other hand, the new (rev. 13) "google_play_services" lib project has some additional packages within com.google.android.gms:
ads
appstate
auth
common
dynamic
games
gcm
internal
location
maps
panorama
plus
wallet
Plus, this package is found in the new (rev. 13) "google_play_services": com.google.ads!
AndroidManifext.xml comparison
The old (rev. 12) "google_play_services" had:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms"
android:versionCode="3265130"
android:versionName="3.2.65 (834000-30)" >
<uses-sdk android:minSdkVersion="8"/>
</manifest>
The newly introduced "google_play_services_froyo" lib project has:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms"
android:versionCode="3225130"
android:versionName="3.2.25 (761454-30)" >
<uses-sdk android:minSdkVersion="8"/>
</manifest>
Conclusion
The "google_play_services_froyo" is functionally the same as the old (rev. 12) "google_play_services" lib project, so if you just want to keep your app compatible and don't care about the new APIs, just import the "google_play_services_froyo" in your project and you're good to go.
On the other hand, if you wanted to use the new (rev. 13) "google_play_services" lib project, once you import it, you have to add this to your apps manifest:
<application
...
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Hope this helped :)
That happened to me yesterday. I just needed to add this in the manifest:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I solved my issue of the same with
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
you have to add the following line in manifest file.
i hope it will work.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I faced this error because I referenced the original copy from SDK directory. Make sure that you first copy the library to android workspace and only reference it. In eclipse you can do it by checking "Copy projects into workspace" while importing the project.
I'm trying my hand and Android Application Development. I'm currently using Eclipse (I can't remember the version, whatever the newest is). I've crossed a bridge where I just can't seem to grasp what I'm doing wrong. I'm attempting to use the Google Maps V2 API. I've been through several documents and tried several techniques, all of which lead to the same error:
Android.view.Inflate Exception: Binary XML file line #2: Error inflating class fragment
I've been pounding my face into the keys for 2 days straight trying to grasp what I'm doing wrong here.
Things I've done:
Started with a blank activity.
Project -> Properties -> Android -> Project Build Target is Google APIs - 4.2 - API 17 - I've tried every other option as well (as long as above version 3.0, found it documented
Added the google-play-services_lib to my Package Explorer. I indicated that the google-play-services_lib was indeed a library.
Project -> Properties -> Android -> Library -> Add -> and I choose the location to the google-play-services_lib.
Included android-support-v4.jar as a dependency of my project.
I've tried so many different answers from questions similar to mine, but to no avail. :(
I can usually figure these things out, but maybe I'm just too overloaded.
My package explorer tree in eclipse looks like
google-play-services_lib
Svma
Here's the code:>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.svma"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.testing.svma.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.testing.svma.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.testing.svma.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="SHA1_Generated_KEY_HERE" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
MainActivity.java
package com.testing.svma;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Reference Documents
I used “Error inflating class fragment” with google map to try and fix my issues.
I referenced This google maps quick start guide to create my project.
I had started initially with the sample code from the Introduction to the Google Maps Android V2 Api
A whole slew of SO questions.
So, SO Community, what am I doing wrong? Why am I unable to grasp this simple concept.
Thank you in advance.
I know this is probably a dead thread but just in case someone stumbles upon here having an identical problem - your manifest might be missing the following meta information:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Declare it within the <application> element and your code should work. I ran into the same issue following a youtube tutorial that skipped this step and only when carefully going through the original Google tutorial I noticed the missing code.
Anyway, hope this helps someone.
I have the same code/same problem! Try adding android:name="com.testing.svma.MainActivity" to "fragment" in the layout! It solved the issue for me
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:name="com.testing.svma.MainActivity"/>
I had the same problem, solved it by modifying the Manifest.
This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.gps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="example.gps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<YOUR VALUE>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="example.gps.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And the xml file is
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
The java class is
public class MainActivity extends FragmentActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
That solved my problem
Try to add google-play-services library reference to your project. If you are using Eclipse, you need to go to Project->Properties->Android and Add google-play-services library project.
ALTERNATIVELY,
You can modify project.properties file manually.
Try to add reference to your google_play_services library. So my project.properties file looks like:
# Project target.
target=android-17
android.library.reference.1=../../../android-sdks/extras/google/google_play_services/libproject/google-play-services_lib
In your case path to google-play-services lib may be different
I tried to import your code and it crashed as well. When I modified properties file - I've got map running
I spend a lot of time trying to solve this problem and after much reading and trying, I solved by changing the
public class MainActivity extends FragmentActivity
for this
public class MainActivity extends android.support.v4.app.FragmentActivity
I hope this can help you
Had tried all the above answers over a period of a couple of days and then eventually this worked:
Project -> Properties -> Android -> Project Build Target
Changed the project build target to android 4.3(API 18) and clicked apply
In the manifest I then manually changed the min and target sdk versions:
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />
This now matches the target=android-18 in the project.properties file (which resulted from the project build target change we did first)
I also tried android:minSdkVersion="11" which worked so the targetSdkVersionis the important bit.
Hope this helps someone!
I had the same problem and I did the mistake to only add one of the 2 following tags.
The actual error is really misleading, as you might be thinking of some API level UI issue.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<YOUR VALUE>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Note that you are also missing one of these two
Frequently the problem is in Manifest.xml , so be sure that you write the right permissions like :
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zako.android.locationapi.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.zako.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- Requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.zako.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.zako.android.locationapi.maps.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="......" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
`
don't forget <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
and <meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
I had a similar error and I think it comes from this point: when I include the Google Play Service API I do not copy it in my workspace, I use the original one !!!
Note: You should be referencing a copy of the library that you copied to your source tree—you should not reference the library from the Android SDK directory.
Check this point.
I have got similar problem that I resolved by right click project->tools>add support library ...
and setup library
I hope this help you
Just include the following line of code on onDestroy()
SupportMapFragment mapFragment = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map_location_sharing));
if(mapFragment != null) {
FragmentManager fM = getFragmentManager();
fM.beginTransaction().remove(mapFragment).commit();
It worked for me.Hopefully gonna work for you too. Thanks
I had this error too and it was due to EXTERNAL PERMISSIONS. It has no sense but I added this permission and since then everything worked fine.
In Some of android 6.0 mobile this exception is bug
If unable to flat XML cause by
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Configuration android.content.res.Resources.getConfiguration()' on a null object reference
Then it is active bug in android
https://issuetracker.google.com/issues/35827842
This can be solved by adding
android:hardwareAccelerated="true" adding in activity tag
using both meta data references was resolving the issue in my case:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="yourAPIkeyFromGoogleAPIConsole" />
I simply added API key to manifest and it helped
I was facing the same problem I just added the API_KEY to Manifest and every thing is fine.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/map_api_key" />