Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error in Android Studio When making a simple Google Android Maps API v2 project

Recently I migrated to the New Android Studio IDE based on IntelliJ

The Guides i followed were:

  1. https://developers.google.com/maps/documentation/android/start (for basics)

  2. How can I create an Android application in Android Studio that uses the Google Maps Api v2? (for importing the required Google Play services and support libraries into android studio)

All the libraries were properly detected by Android Studio and i didn't get any 'library not found errors'. The project was shown error free. Then when i tried to compile it i got this error.

Gradle: 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':AID-AmritaInfoDesk:compileDebug'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.

This was my explorer.java file

package com.aid.explorer;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;


public class explorer extends FragmentActivity {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.explorer);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }


    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }


    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }
}

And this was my explorer.xml file

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.SupportMapFragment"/>

I would like to know what went wrong. any help would be greatly appreciated

like image 687
niranjan94 Avatar asked May 19 '13 11:05

niranjan94


People also ask

What are the permissions required for setting up the Google Maps app in AndroidManifest XML file?

If your app needs to access the user's location, you need to request the location permission in your AndroidManifest. xml file. The options are ACCESS_FINE_LOCATION , which provides the precise user location, and ACCESS_COARSE_LOCATION , which is less precise. For details, see the location data guide.

Which permission you will specify for using Google map?

Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION . The permission you choose determines the accuracy of the location returned by the API. android.


1 Answers

I was following the same instructions except I was creating a new project. Under the project structure I removed the Android-Gradle facet and was able to build successfully. Optionally one can update the gradle build files and add the Android-Gradle facet to the play services library.

NOTE: I changed the name of Google Play Services directory.

build.gradle for Google Play Services library.

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('google-play-services.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion '17.0.0'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aild.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

build.gradle for test app.

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':lib-google-play-services')
    compile files('../lib-google-play-services/libs/google-play-services.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 16
    }
}
like image 93
Frohnzie Avatar answered Oct 16 '22 01:10

Frohnzie