NoClassDefFoundError at Google Play Services V2 library

后端 未结 8 1264
無奈伤痛
無奈伤痛 2020-11-28 11:27

I get the following exception when trying to use the Google Play Services V2 library after following the official tutorial.

java.lang.NoClassDefFoundError: c         


        
8条回答
  •  执念已碎
    2020-11-28 12:30

    I also have the same issues once ,I followed the step properly and able to solve this issue

    First (Set up your project from Google Developer console) Go to API Console - Google Code

    Create A project As shown in the images enter image description here

    Click Create then you will Ask to add a project name as shown

    enter image description here

    once you create your project its time to select what service we need to use,In this case we need android v2 map so select the Google Maps Android API v2 from Service As shown, enter image description here

    Now go to Api Access and create your OAuth 2.0 .By provide your package name and SHA1 fingerprint in the corresponding fields. enter image description here

    once you finish with OAuth 2.0 we are ready to use your API Key enter image description here

    Now Create An Android project with the same package name used while creating the OAuth 2.0. and Check whether you have the google play service in Android SDK Manager otherwise install google play service. enter image description here

    After installing Google playservice you will find a Google play library in Your Android YourSdkpath\extras\google\google_play_services.Import that project to your workspace and give it as the refrence library to your project enter image description here

    enter image description here

    enter image description here

    After that put the corresponding java and xml files to your project.

    MainActivity.java

    package yourpackage;//Package name used while creating the Api key
    
    
    import com.google.android.gms.common.ConnectionResult;
     import com.google.android.gms.common.GooglePlayServicesUtil;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.Dialog;
    import android.support.v4.app.FragmentActivity;
    import android.view.Menu;
    
    public class MainActivity extends FragmentActivity {
    GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // Getting status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
    
        // Showing status
        if(status==ConnectionResult.SUCCESS)
        {
            SupportMapFragment supportMapFragment = (SupportMapFragment) 
                    getSupportFragmentManager().findFragmentById(R.id.map);
    
            // Getting a reference to the map
            googleMap = supportMapFragment.getMap();
        }
        else{
    
            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();
        }
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    }
    

    activity_main.xml

    
    

    AndroidManifest.xml

    
    
    
    
       
    
    
    
    
    
    
    
    
    
    
    
    
        
            
                
    
                
            
        
          
    

    Hope it will help you

提交回复
热议问题