I try to create a simple GoogleMap by Using Google Play Service and Google Maps API. But all the times I get errors...
I´m working with IntelliJ 12.1, here my full Code:
RecorderMap.java
package com.example.GPSApp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class RecorderMap extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
map.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.SupportMapFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.GPSApp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<permission
android:name="com.example.GPSApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MainActivity"
android:label="#string/app_name"
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>
<activity android:name=".RecorderMap"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXX" />
</application>
</manifest>
I think the Problem is how I include the GooGlePlayService... I´ve tried to add as module, as libary as External Libary but I don't know how to include and to use it right... :(
EDIT:
LogCat
08-28 07:41:59.869: ERROR/AndroidRuntime(23080): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GPSApp/com.example.GPSApp.RecorderMap}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
at android.app.Activity.setContentView(Activity.java:1660)
at com.example.GPSApp.RecorderMap.onCreate(RecorderMap.java:18)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: SupportMapFragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 20 more
****EDIT2**
Problem solved by using this: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable**
The only thing I find missing in your RecorderMap.java file is that you haven't imported the SupportFragment class. So add this line to it
import com.google.android.gms.maps.SupportMapFragment;
If that doesn't work, then check out the following.
From what you are saying, it means you have already installed the google play services. If not, then try installing it using this link http://developer.android.com/google/play-services/setup.html
After that, referencing the google play services library should be as easy as editing your build.gradle file. The current version of android studio makes this possible. Under dependencies in your build.gradle file, add the following code
compile 'com.google.android.gms:play-services:3.1.36'
You seem to have your API key intact.
Finally, remember you need to test your app on an actual android device and not an emulator. The android API version 2 is not yet able to display maps on emulators.
I think this should be okay for your app to work.
Related
I do not know, what i am doing wrong in either my manifest, activity or xml to load map version 2,
i found multiple exceptions if you see my concise logcat,
E/AndroidRuntime(16522): FATAL EXCEPTION: main
E/AndroidRuntime(16522): java.lang.RuntimeException: Unable to start activityComponentInfo{com.production.MyApp/com.project.MyApp.AddEvent.AddEventMapActivity}:
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
E/AndroidRuntime(16522): at android.app.Activity.setContentView(Activity.java:1892)
E/AndroidRuntime(16522): at com.project.MyApp.AddEvent.AddEventMapActivity.onCreate(AddEventMapActivity.java:20)
E/AndroidRuntime(16522): 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" />
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
E/AndroidRuntime(16522): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
while manifest looks like,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.production.MyApp"
android:versionCode="3"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name=" com.production.MyApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name=" com.production.MyApp.permission.MAPS_RECEIVE" />
<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-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="com.project.MyApp.MyApplication"
android:enabled="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="no issue with api_key here" />
and xml,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
while i am extending FragmentActivity,
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
You need to add the below to manifest file
<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.
Check out HERE
It's a new requirement added from the last revision 13 update to google-play-services.
You need to add the following in your manifest
...
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
This information can be found in the logcat error msg.
And also on google play services website
I am trying to get Google Maps Android API v2 working on Android 2.2 on a HTC Desire.
My main.xml contains the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.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>
This is my activity.
package dk.sw510e13.user;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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;
}
}
When I run the application, I will get the following exception. It seems that it cannot find SupportMapFragment, however, I believe that I have both the support library and Google Play Services as dependencies. When creating the project in Android Studio I chose to add support for fragments.
01-17 23:52:55.237 2557-2557/dk.sw510e13.user E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.sw510e13.user/dk.sw510e13.user.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
at android.app.Activity.setContentView(Activity.java:1654)
at dk.sw510e13.user.MainActivity.onCreate(MainActivity.java:13)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/data/app/dk.sw510e13.user-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
... 23 more
This is what I have in my dependencies.
Can anyone tell me what I am doing wrong?
UPDATE
This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<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"/>
<!-- 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"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.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="XXXXXX"/>
</application>
</manifest>
This is the problem that seems to be occurred when missing Google Play services.
I request you to please follow the steps mentioned below to get the Google Play services to be included in your application.
copying the google-play-services.jar in libs folder and set in the build path of eclipse is a wrong method.
import Google Play services in your project and add it in workspace.
from location of your SDK folder.
\extras\google\google_play_services\libproject\google-play-services_lib
2! Now you added Google Play Services to your work space, we have to create a reference
from our project to this library. Right-Click your project and choose “Properties” go
to the Android section, in the lower part press the “Add…” button and add a reference
to that library. Your result should be as in the screen shot bellow:
adding Google Play services library
Please Add
<permission
android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
in your manifest
I'm creating sample application to use Google Maps Android API v2.
I tried on Samsung Galaxy Ace GT-S5830i, but instead of Map, I'm seeing
And logcat is
Signature not valid. Found:
MIIDDTCCAfWgAwIBAgIEEhX+gTANBgkqhkiG9w0BAQsFADA3MQswCQYDVQQGEwJVUzEQMA4GA1UE
ChMHQW5kcm9pZDEWMBQGA1UEAxMNQW5kcm9pZCBEZWJ1ZzAeFw0xMzAyMjUxMTEwNDRaFw00MzAy
MTgxMTEwNDRaMDcxCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdBbmRyb2lkMRYwFAYDVQQDEw1BbmRy
b2lkIERlYnVnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApqChoDnHsDfsxa7n2Kv9
2av0G0tm+kS1uP4T6fA8cO6jB3qB5EHFR6+5UO+k4laHW2WzOJbyhhtFE5eOTS4Zt5qo4FX/hsc/
Zi7dDX/Y13b+4qajhLoGYqVjM00eQc2qF58TTnbQ3lTERxaofYL2qI3j2KcVODFMksinL9lt3RTD
V3MXy7KDLcuSvoVZxXn1L0O9rkTbZicmleK4wLDzI+lTpuXngAuQ4MBH1wEWwqMhJg6/J06t5axU
ea2UVv7ZtYg8KPMEiQEApCbdAHtQsmqcsEQZtJAqFtj7KEQ7wTSgnpDRix4N5C9QlwUtKSlOCIlk
ueUPVBypKf/SWIgF6QIDAQABoyEwHzAdBgNVHQ4EFgQURyMuspjlLaDj8LhEb5UyYqQgWQYwDQYJ
KoZIhvcNAQELBQADggEBAA9IXLEAQTD+VEt9l8JQDEOFv8WqIdQisvmJCfJjN98faarvf6RRA+v3
HF2VFlZPaUu/HBeOH8MI7u+gNuRtZGYWn1eC/qfP0W31MQoNaN4ocsF+tL9INzpd89/u6Ya5Kove
r0E0tpJFBgdtDPYcPBjQ6tYAqmhnmPIJftGHLNQbil4ocK/PkqgxGlwQN7WrCNjDewb0twz7hZBx
Ig4OsnfdgPTYGlR+LyTzUd9/KyqaLHivRAI+y/xGDz6lOfGH7bDOPi/hDm0bkhC1y1J7L9+FiGWb
dmi+Co9Jlf1f3vyTtD7kr3h0K0C3MsNWtybVqmVvgImoLt/lPbjNJahVrds=
Google Play services signature invalid.
Can't open keycharmap file
Error loading keycharmap file
Using default keymap
My manifest code
<?xml version="1.0" encoding="utf-8"?>
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.testmap.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<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" />
<permission
android:name="com.example.testmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<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="AIzaSyDTsWrO0j24sbp4E5qhoHhd6nyOQM5lErc" />
<activity
android:name="com.example.testmap.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>
my xml file code
<?xml version="1.0" encoding="utf-8"?>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
My activity code
package com.example.testmap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.final_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//map.getMinZoomLevel();
}
}
And clicking on ok button gives force close with Logcat
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
at android.app.Activity.startActivityForResult(Activity.java:2827)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:2933)
at com.google.android.gms.internal.e$2.onClick(Unknown Source)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Also when I UN-comment last line map.getMinZoomLevel(); , I get null pointer exception on the line.
Check if you have enabled offline work for gradle: Goto File > Settings > Gradle
Deselect Offline Work if its checked.
Then confirm if you have latest version of google services mentioned as dependencies in project level build.gradle:
classpath 'com.google.gms:google-services:2.1.0'
You can find latest version here: https://jcenter.bintray.com/com/android/tools/build/gradle/
Clean and build the project after gradle sync completes.
ouThese steps solved a similar issue I'd with Google Maps and also solved the first error you mentioned Signature Not Valid
If your device runs on Android M, you may want to verify your code for location access following this answer.
I was also getting same exception and I fixed it.
Note: I am working on google analytics and was getting this exception. But my app was not crashing I was getting this in Logs. you can also try this solution.
add this in project level gradle file.
classpath 'com.google.gms:google-services:2.1.0'
and this one for module level gradle file.
compile 'com.google.android.gms:play-services:8.4.0'
and move `below plugin at the end of file (at last line) of module level gradle file.
apply plugin: 'com.google.gms.google-services'
I have just implemented a map in the application, and it runs flawlessly in a Galaxy S3. Testing my app with an old phone HTC Sense with API8 the app throws a inflator problem. I think it may be related to either the OS or OGL2. isGooglePlayServicesAvailable(this) returns a correct value. Help me here, please:
Activity.java
public class MyActivity extends Activity
{
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.initializeInterface();
}
private void initializeInterface() {
final int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
this.setContentView(R.layout.main);
}
}
main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
class="com.google.android.gms.maps.MapFragment"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header" />
manifest.xml
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.stuff.permission.MAPS_RECEIVE" />
<permission
android:name="com.stuff.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/icon"
android:label="#string/application_name" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/map_api_key_device"/>
<activity
android:name=".MyActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
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>
</application>
Error
12-13 12:14:13.865: E/My ERROR(22878): Binary XML file line #85: Error inflating class fragment
12-13 12:14:13.875: E/android.view.LayoutInflater.createViewFromTag(22878): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
12-13 12:14:13.895: E/android.view.LayoutInflater.rInflate(22878): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-13 12:14:13.935: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-13 12:14:13.945: E/com.android.internal.policy.impl.PhoneWindow.setContentView(22878): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
12-13 12:14:13.945: E/android.app.Activity.setContentView(22878): at android.app.Activity.setContentView(Activity.java:1654)
It has to do with the fact that you are trying to use native API Level 11 fragments on an API Level 8 device. Switch to FragmentActivity and SupportMapFragment if you wish to have your code work on earlier versions than Android 3.0.
I solved this problem by adding the v13 libraries from /extras/android/compatibility/v13 and changing my Activity to FragmentActivity and MapFragment to SupportMapFragment.
for me help app project -> right click -> properties -> android -> project build target -> and chack earlier android release. (with google api)
if you dont have, download one by SDK manager
I have built an application for a large multicultural festival in my city that kicks off on Saturday. I've tweaked a lot of bugs in the iPhone version and we are waiting for Apple to approve it. I have taken that perfected version as the basis for the Android version.
The Android version looks and works great. I can run it on my Samsung Galaxy S II by either "Run as Android Application" in Eclipse or by uploading it to a server and downloading it into the phone. I can also email the app to myself and it works, too. I submitted it to the Google Play store and once it got into the wild (this is advertised on billboards, buses, everywhere) it crashes the minute it is opened.
I'm not really sure how to troubleshoot this when it works fine on the device before publication. I read about how it has to do with the MainActivity activity name, but everything looks like it lines up.
Error 1 [ClassNotFoundException in PathClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader
dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
Error 2 [ClassNotFoundException in BaseDexClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
Any help would be greatly appreciated! I am in quite the pickle.
Edit - Here is the AndroidManifest.xml from the bin folder
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="false" android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<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_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="#string/share_name">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
It turned out my main Java file was named "MainActivity.java" but it was being called as "Folklorama.java" throughout the project files. I renamed the file to Folklorama.java.