Document Location SDK for Android Guides Set Up Your Project Set Up in Android Studio

Set Up in Android Studio

This guide explains how to configure an Android Studio project to integrate the location SDK. You can choose either the manual copy method or the Gradle integration method.

Prerequisites

Before you begin, create a new Android project with an Empty Activity. For detailed instructions, see Creating a Project in the Getting Started guide.

Method 1: Manual SDK Integration

Step 1: Copy the JAR file to the libs folder

Copy the location SDK JAR file to the libs directory of your project. If an older version of the location JAR file exists, delete it first. The location SDK does not require SO library files.

Android Studio project structure showing the JAR file copied into the libs directory for manual SDK integration

Step 2: Configure the build.gradle file

Add the following dependency to the dependencies block in your module-level build.gradle file:

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

Android module-level build.gradle file showing the compile fileTree dependency configuration for JAR libraries

Method 2: Gradle SDK Integration

Step 1: Configure the repository in the project-level build.gradle

Android Studio automatically adds the JCenter repository for all modules in the project-level build.gradle file. If it already exists, no additional configuration is needed.

Android project-level build.gradle file showing the Maven repository configuration for Gradle SDK integration

Add the following configuration:

allprojects {
    repositories {
        jcenter() // or mavenCentral()
    }
}

Step 2: Add dependencies in the module-level build.gradle

Add the SDK dependencies based on your project requirements. The following table lists the available SDKs and their corresponding dependency declarations:

SDK

Dependency Declaration

3D Map

compile 'com.amap.api:3dmap:latest.integration'

Navigation

compile 'com.amap.api:navi-3dmap:latest.integration'

Search

compile 'com.amap.api:search:latest.integration'

Location

compile 'com.amap.api:location:latest.integration'

Android build.gradle dependencies block showing the AMAP Location SDK compile dependency declaration

The following example shows how to configure the 3D Map, Location, and Search SDKs for a 3D map demo project:

android {
   defaultConfig {
       ndk {
           // Specify the supported SO library architectures.
           // You can select one or more platforms as needed.
           abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "arm64-v8a", "x86_64"
        }
   }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // 3D Map SDK (includes SO libraries and JAR)
    compile 'com.amap.api:3dmap:latest.integration'
    // Location SDK
    compile 'com.amap.api:location:latest.integration'
    // Search SDK
    compile 'com.amap.api:search:latest.integration'
}

Note: Using the latest version is recommended. To use a specific version, replace latest.integration with the version number, as shown below:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.amap.api:3dmap:5.0.0'
    compile 'com.amap.api:location:3.3.0'
    compile 'com.amap.api:search:5.0.0'
}

Important Notes

1. Multi-platform SO library support: The 3D Map SDK and Navigation SDK (version 5.0.0 and later) fully support multiple SO library architectures (armeabiarmeabi-v7aarm64-v8ax86x86_64). You can choose the architectures that match your needs. When upgrading from an older version, remove the old SO libraries before adding the new ones.

2. Navigation SDK includes 3D Map SDK: The Navigation SDK (version 5.0.0 and later) includes the 3D Map SDK. Do not add both 3dmap and navi-3dmap dependencies simultaneously.

3. Build failures: If a build fails with an error indicating that a dependency (e.g., com.amap.api:XXX:X.X.X) cannot be found, verify the spelling and version number. If the JCenter repository is inaccessible, try switching to the Maven Central repository.

4. Avoid duplicate dependencies: After integrating the SDK using Gradle, do not manually copy the corresponding SO libraries and JAR files into the libs folder, as this will cause conflicts.