0

I just want to call my Default MapsActivity in Android Studio when user clicks Maps from NavigationDrawer in MainActivity.

For Maps,I am using template in Android studio.When i am trying to build the application,it shows

Execution failed for task':app:transformClassesWithDexForDebug

Here i include my Error Screenshot,my MapsActivity Code. In my Android Studio,I have already installed google play service in SDK manager and i also get google API key for Google Map and i include it in google_maps_api.xml.

Please help me

MapsActivty

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

activity_maps.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ajay.com.dhruvafest.MapsActivity" />

I think these code are enough..I referred this from https://developers.google.com/maps/documentation/

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "ajay.com.dhruvafest"
        minSdkVersion 14
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    dexOptions {

        javaMaxHeapSize "4g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
}

AndroidManifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Splash"
            android:launchMode="standard"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Home"
            android:label="Home"
            android:largeHeap="true"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".Policies" />
        <activity android:name=".Events" />
        <activity android:name=".EventList" />
        <activity android:name=".EventDet" />
        <activity android:name=".Sponsors" />
        <activity android:name=".Workshops" />
        <activity android:name=".Developers" />
        <activity android:name=".Schedule" />
        <activity android:name=".Contact" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"></activity>
    </application>
</manifest>

Updated Error Screenshot enter image description here

Ajay Jayendran
  • 1,584
  • 4
  • 15
  • 37
  • please remove compile 'com.google.android.gms:play-services:10.0.1' becuase you are using 'compile 'com.google.android.gms:play-services-maps:10.0.1' – Yogesh Borhade Dec 29 '16 at 04:07

4 Answers4

0

Add multiDexEnabled true in your app.gradle file

defaultConfig {
     multiDexEnabled true
}
Mihodi Lushan
  • 670
  • 5
  • 24
0

The following steps are needed to start multi dexing:

Add android-support-multidex.jar to your project. The jar can be found in your Android SDK folder /sdk/extras/android/support/multidex/library/libs

or

Try adding the following to your gradle,

defaultConfig {
     multiDexEnabled true
}

add in dependencies,

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

Now let your apps application class extend MultiDexApplication

public class MyApplication extends MultiDexApplication
Deep Patel
  • 2,584
  • 2
  • 15
  • 28
0

step 1 please check below code and add this code in your gradle.

 dexOptions {

        javaMaxHeapSize "4g"
    }

step 2 in defaultConfig add

 multiDexEnabled true

step 3 in dependencies compile

 compile 'com.android.support:multidex:1.0.1'

step 4 Please refer below code

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"

        defaultConfig {
            applicationId "com.jmtechnologies.askuscash"
            minSdkVersion 11
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
// ADD BELOW LINE
            multiDexEnabled true

        }
// BELOW LINE FOR HEAP SIZE
        dexOptions {

            javaMaxHeapSize "4g"
        }

    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:multidex:1.0.1'

    }

if still error will occur please update your gradle file here i need to check gradle file

Yogesh Borhade
  • 694
  • 1
  • 10
  • 24
0

1)Please check below is my gradle file and this gradle file work fine for me.

2) for google map you are using

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

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

3) please remove compile 'com.google.android.gms:play-services:10.0.1'

step 4 update your gradle file using below code i have do changes in that.

   apply plugin: 'com.android.application'

android {

    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "ajay.com.dhruvafest"
        minSdkVersion 16
        targetSdkVersion 25
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    dexOptions {

        javaMaxHeapSize "4g"
    }
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
}

follow step 5 and 6 if above gradle file is not working

step 5 check below gradle file which i have checked and its working fine in Build.Gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"


    defaultConfig {
        applicationId "ajay.com.dhruvafest"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        //if 2g or 4g
        javaMaxHeapSize "2g"
    }

    // important to run code on kitkat

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    // multidex
    compile 'com.android.support:multidex:1.0.0'


    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'


    // Map
    //compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.maps.android:android-maps-utils:0.3+'


    // Volley
    compile 'com.android.volley:volley:1.0.0'

    //Firebase
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'

    //CropImage
    compile project(':CropImage')


}
apply plugin: 'com.google.gms.google-services'

Step 6 and in Build.Gradle(Project:Your project name) file

you need to add this line
classpath 'com.google.gms:google-services:3.0.0'

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'

    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Yogesh Borhade
  • 694
  • 1
  • 10
  • 24