Bob Dylan Bob Dylan - 1 month ago 37
Android Question

How to run Google Map?

What am I doing wrong?
I literally used the provided templated for google maps.

public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback { /** Templated provide by google */}


I got an API key for the project. However when I run it, here is my error:

Error:Gradle: Execution failed for task ':app:transformClassesWithDexForDebug'.



com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2


Additional Error:

Information:Gradle: Executing tasks: [:app:assembleDebug]
Information:Kotlin: Kotlin JPS plugin is disabled


Gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "com.huyvo.testermap"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
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.google.android.gms:play-services:9.6.1'
}

Answer

You should not use all of Google Play Services.

Instead, you should selectively use only the parts that you need.

For Google Maps, you'll likely just need maps and location:

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