0

I am trying to use google map in my android app for learning purpose . I generated the api key but i am getting this 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

How do i rectify errors ?I am new to android app development so please bear with me .

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.user.googlemap">

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <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">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="my api key ,i have put it over 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>

</manifest>

here is gradle build file as asked by zombie .

apply {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.user.googlemap"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }a
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.google.android.gms:play-services:10.0.1'
    testCompile 'junit:junit:4.12'
}

After making changes , now i am getting this error . * What went wrong: A problem occurred evaluating project ':app'.

Could not find method compileSdkVersion() for arguments [25] on project ':app' of type org.gradle.api.Project.

  • Try:
i_love_pizza
  • 1
  • 2
  • 4

2 Answers2

0

Your error... DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them

Google Play Services Setup (emphasis mine)

You are indeed compiling "all of them"

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

You only seem to need Maps?

Then only compile -maps.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.google.android.gms:play-services-maps:10.2.0' // See here
}

(Or you can enable Multidex... but that is overkill for the current issue)


Then, I don't know what you did to the Gradle, file, but

apply { // <-- Should be android
    compileSdkVersion 25

    ... 

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }a // <--- Remove this random 'a' character
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
0

I got similar issue today, after I changed minSdkVersion from 15 to 21, and add line multiDexEnabled true then works fine, more information please check here https://developer.android.com/studio/build/multidex.html, looks like this issue is caused by Multidex support.

  • It works fine after one more line " multiDexEnabled true" was added – Jacky wang Feb 23 '17 at 03:37
  • ensure **multiDexEnabled true** and **minSdkVersion 21** in the gradle file, under defaultconfig section, because this comment editor is very limited for me, I don't know how to format the text good here, but I think you should know how to change it – Jacky wang Feb 23 '17 at 06:19