3

I want to make an application that uses the Google Maps API, I started with a simple application that opens a google map activity. (I download google play services from the SDK Manager). I think that it's a very basic program but there is an error when I try to run my application.

Here's the code of my program, and also the error generated by Android Studio.

The error:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

The code:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {     
private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
<resources>

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">My API key is here ;) </string>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amine.bea_mapapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="My API key is here ;)" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • Sorry for the error image, the error is : Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 – LALMI Mohamed Lamine Jul 04 '16 at 05:28
  • See this for reference http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ – Shahbaz Hashmi Jul 04 '16 at 05:39
  • You can do this. http://stackoverflow.com/a/32811133/5296734 this may help you. – android_griezmann Jul 04 '16 at 06:18

3 Answers3

6

This is a common error when you import all of Google Play Services, if you do, it's easy to hit the 65k method limit.

If you have this in your build.gradle:

compile 'com.google.android.gms:play-services:10.0.1'

Replace it with this:

compile 'com.google.android.gms:play-services-maps:10.0.1' 

For more info see the documentation.

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
0

add internet permission in manifest file

 <uses-permission android:name="android.permission.INTERNET"/>

also make sure you turn on internet and location on your phone

Manohar
  • 22,116
  • 9
  • 108
  • 144
-1

Yes after adding Internet permission try to add multiDexEnabled true to your app build.gradle file.

defaultConfig {
    multiDexEnabled true
}
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
Chirag Arora
  • 816
  • 8
  • 20
  • This error occurs only when our libraries are conflict and give multipleDex error. If you don't want to enable multiple dex then you also check the below link. http://stackoverflow.com/questions/32798816/unexpected-top-level-exception-com-android-dex-dexexception-multiple-dex-files – Chirag Arora Jul 04 '16 at 07:29