0

I am working on a project using Google Maps v2 for Android and I am getting a NoSuchFieldError while instantiating the Google map fragment on a rooted HTC Desire HD.

Afaik, the issue should not be caused by Google Play Services not being installed on the device (event though they are and other applications using Google Maps v2 are working).

I have tried making a check to see if Google Play Services library is installed on the device (by calling GooglePlayServicesUtil.isGooglePlayServicesAvailable) prior to setting the Activity's content view.

Furthermore, the application runs on other Android phones and the map fragment is successfully inflated.

At the moment I suspect that this issue is caused by my Android project setup in Eclipse, as the Google Play Services library project seems not to be included along with my project during packaging or deployment.

Has anyone had and solved this issue with Google Maps working only on some devices and throwing a NoSuchFieldError exception on others? If so, what can I do to solve this?

If you need more information such as project setup and/or code, please leave a comment.

Thank you!

This is the stack trace report from ACRA in JSON format:

{ CUSTOM_DATA: '', STACK_TRACE: 'java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text\n\tat com.google.android.gms.common.GooglePlayServicesUtil.b(Unknown Source)\n\tat com.google.android.gms.internal.bb.a(Unknown Source)\n\tat com.google.android.gms.internal.bb.onCreateView(Unknown Source)\n\tat com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)\n\tat android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)\n\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)\n\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)\n\tat android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)\n\tat android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)\n\tat android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)\n\tat android.view.LayoutInflater.rInflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\n\tat com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)\n\tat android.app.Activity.setContentView(Activity.java)\n\tat ro.myapp.app.activities.MapActivity.onCreate(MapActivity.java:62)\n\tat android.app.Activity.performCreate(Activity.java)\n\tat android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)\n\tat android.app.ActivityThread.performLaunchActivity(ActivityThread.java)\n\tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)\n\tat android.app.ActivityThread.access$600(ActivityThread.java)\n\tat android.app.ActivityThread$H.handleMessage(ActivityThread.java)\n\tat android.os.Handler.dispatchMessage(Handler.java)\n\tat android.os.Looper.loop(Looper.java)\n\tat android.app.ActivityThread.main(ActivityThread.java)\n\tat java.lang.reflect.Method.invokeNative(Native Method)\n\tat java.lang.reflect.Method.invoke(Method.java)\n\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)\n\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java)\n\tat dalvik.system.NativeStart.main(Native Method)\n', PHONE_MODEL: 'HTC Desire HD', ANDROID_VERSION: '4.0.4' }

This is my onCreate method throwing the exception:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    checkForPlayServices();

    setContentView(R.layout.activity_map);
    mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
    map = mapFragment.getMap();
    map.setMyLocationEnabled(true);
    map.setInfoWindowAdapter(this);
    map.setOnInfoWindowClickListener(this);
}

Contents of activity_map.xml layout:

<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=".MapActivity" >

    <ro.myapp.app.views.actionbar.ActionbarMap
        android:id="@+id/actionBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/myapp_actionbar_height" />

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/actionBar"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 
lucian.pantelimon
  • 3,673
  • 4
  • 29
  • 46
  • Can you also post your method where it is getting the error. – yams Jul 01 '13 at 19:39
  • Posted. It has nothing "special" in it. Line #62 causing the crash is the line with the call to `setContentView(R.layout.activity_map);`. I also make an asynchronous web request after `map.setOnInfoWindowClickListener(this);` which I have removed from the code posted here. Nothing else is done in the `onCreate` method. The layout contains one other view (a `RelativeLayout` with two `ImageView`s and a `TextView`) – lucian.pantelimon Jul 01 '13 at 19:45
  • Ok can you post the layout.xml file for the same class. It seems you maybe using the wrong id. Or you have the MapFragment versus SupportMapFragment on your layout.xml file. – yams Jul 01 '13 at 20:01
  • Posted. The `ActionbarMap` is a `RelativeLayout` as specified above. I am using it in place of an action bar in order to integrate with SlidingMenu (and have the desired behavior) in other activities. In this `Activity`, I am using this layout in order to preserve consistency. – lucian.pantelimon Jul 01 '13 at 20:07

2 Answers2

2
java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text

says exactly what is the problem.

In values/strings.xml there is no

<string name="common_google_play_services_unsupported_text">...</string>

defined.

I see this value defined in my google-play-services_lib/res, so you may want to check if you correctly added this library project to your workspace. Seems like you have forgot to update strings.xml when updating library.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • Re-downloading and re-importing the library worked. Unfortunately Google Play Services library detects some rooted devices as "unsupported", but now I can display a `Dialog` informing the user of what went wrong. Thank you! – lucian.pantelimon Jul 09 '13 at 13:16
0

Ok so I changed my answer I found out there is a way to find out if there is anything overriding your libs.... You are using the Location Objects somewhere so add this bit of code and debug it when running one of those devices..... The location object should be in your location listener.

 location.getClass().getProtectionDomain().getCodeSource().getLocation() ;
yams
  • 942
  • 6
  • 27
  • 60
  • The code is pretty much the same. The code I've posted works on most devices, but has some issues on a couple of rooted devices. The HTC Desire HD is one of them, can't remember what the other one was as I've deleted the crash log for it and it was reported in production (one of the Galaxy Mini models, don't remember which). – lucian.pantelimon Jul 01 '13 at 20:10
  • Are you using a locationmanager as well? I make sure to get the location manager first. – yams Jul 01 '13 at 20:11
  • Yes. In my `onResume` method I set that up so that it updates when the user gets back to this `Activity`, but on the two phones, the code does not make it as far as `onResume`, so it shouldn't be part of this issue's cause. Also, it should be possible to instantiate the map without instantiating the `LocationManager` as I've done that in a previous app – lucian.pantelimon Jul 01 '13 at 20:13
  • This error could be thrown because of redraw. I use a map.clear() in the onResume. – yams Jul 01 '13 at 20:14
  • `onResume` is not called. I use `clear()` in `onPause` in order to clear up memory, as the map has lots of markers which include images set up after the asynchronous HTTP request completes and not doing so will crash the application on devices with low memory (16 MB). – lucian.pantelimon Jul 01 '13 at 20:17
  • Check your JRE/lib or JRE/lib/ext folders. Make sure there isn't any jars that override your jars. – yams Jul 01 '13 at 20:24
  • Ok I changed my answer take a look and see what you can find. – yams Jul 01 '13 at 20:44
  • Hmm ... I do find that there are two Google Play Services jars in the project's `/bin/dexedLibs/` folder, but I can't find where each is coming from... – lucian.pantelimon Jul 01 '13 at 20:45