Migrate to Android Studio

Migrating your projects to Android Studio requires adapting to a new project structure, build system, and IDE functionality. If y'all are migrating an Android project from Eclipse, Android Studio provides an import tool so you can quickly move your existing code into Android Studio projects and Gradle-based build files. For more than data, see Migrating from Eclipse.

If you are migrating from IntelliJ and your project already uses Gradle, you can simply open your existing project from Android Studio. If yous are using IntelliJ, but your project does not already use Gradle, you will need to do a little bit of manual preparation before you tin import your projection into Android Studio. For more information, see Migrating from IntelliJ.

Android Studio basics

Here are some of the key differences yous should be enlightened of as y'all prepare to drift to Android Studio.

Project and module organization

Android Studio is based on the IntelliJ IDEA IDE. To get familiar with the IDE basics, such as navigation, code completion, and keyboard shortcuts, meet Run into Android Studio.

Android Studio does non use workspaces, so separate projects open up in separate Android Studio windows. Android Studio organizes code into projects, which contain everything that defines your Android app, from app source code to build configurations and test code. Each projection contains ane or more modules, which allow y'all to separate your projection into detached units of functionality. Modules can be independently built, tested, and debugged.

For more information about Android Studio projects and modules, see the Projects overview.

Gradle-based build organisation

Android Studio's build system is based on Gradle and uses build configuration files written in Groovy syntax for ease of extensibility and customization.

Gradle-based projects offer meaning features for Android development, including the following:

  • Back up for binary libraries (AARs). You no longer need to copy library sources into your ain projects, yous can simply declare a dependency and the library is automatically downloaded and merged into your projection. This includes automatically merging in resources, manifest entries, proguard exclusion rules, custom lint rules, and so on at build time.
  • Support for build variants. For example, build variants let you build different versions of your app (such as a costless version and a pro version) from the same project.
  • Easy build configuration and customization. For example, you can pull version names and version codes from Git tags as part of the build.
  • Gradle tin can exist used from the IDE only too from the command line and from continuous integration servers like Jenkins, providing the same build everywhere, every time.

For more information well-nigh using and configuring Gradle, see Configure your build.

Dependencies

Library dependencies in Android Studio apply Gradle dependency declarations and Maven dependencies for well-known local source and binary libraries with Maven coordinates. For more information come across, Configure build variants.

Exam code

With Eclipse ADT, instrumentation tests are written in separate projects and integrated through the <instrumentation> element in your manifest file. Android Studio provides an androidTest/ directory in your projection's primary sourceset so you can hands add and maintain your instrumentation test code within the same project view. Android Studio also provides a test/ directory in your project's primary sourceset for local JVM tests.

Migrating from Eclipse

Android Studio offers an automatic import tool for existing Android projects created using Eclipse.

Migration prerequisites

Before migrating your app from Eclipse to Android Studio, review the following steps to make sure your projection is ready for conversion, and verify you have the tool configuration you need in Android Studio:

In Eclipse ADT:

  • Make sure the Eclipse ADT root directory contains the AndroidManifest.xml file. Also, the root directory must incorporate either the .project and .classpath files from Eclipse or the res/ and src/ directories.
  • Build your project to ensure your latest workspace and project updates are saved and included in the import.
  • Comment out whatsoever references to Eclipse ADT workspace library files in the project.properties or.classpath files for import. You lot can add these references in the build.gradle file after the import. For more information, see Configure your build.
  • It may be useful to record your workspace directory, path variables, and any bodily path maps that could be used to specify any unresolved relative paths, path variables, and linked resource references. Android Studio allows you to manually specify whatever unresolved paths during the import procedure.

In Android Studio:

  • If you don't have it, download Android Studio. If you do have Android Studio, verify that information technology is the latest stable release by clicking Aid > Bank check for Updates (on Mac, Android Studio > Check for Updates).
  • Considering Android Studio does non migrate any third-party Eclipse ADT plugins, brand a annotation of any tertiary-party plugins you lot utilize in Eclipse. You can check for equivalent features in Android Studio or search for a compatible plugin in the IntelliJ Android Studio Plugins repository. Use the File > Settings > Plugins menu pick to manage plugins in Android Studio.
  • If yous plan to run Android Studio behind a firewall, be sure to ready the proxy settings for Android Studio and the SDK Manager. Android Studio requires an internet connexion for Setup Sorcerer synchronization, 3rd-party library admission, access to remote repositories, Gradle initialization and synchronization, and Android Studio version updates. For more information, meet Proxy settings.

Import Eclipse projects to Android Studio

You should decide how you will import your existing Eclipse ADT projects depending on their structure:

  • If you take multiple related projects sharing the same workspace in Eclipse ADT, import the first project as a project, and then add subsequent related projects as modules within that project.
  • If your Eclipse ADT projects share dependencies within the same workspace merely are not otherwise related, import each Eclipse ADT project individually into Android Studio as a split project. Android Studio maintains the shared dependencies across the newly created projects as part of the import procedure.
  • If your Eclipse ADT project includes native (C/C++) libraries, meet Link Gradle to your native library for instructions on how to include your native libraries as Gradle build dependencies.

Import as a project:

  1. Start Android Studio and shut any open Android Studio projects.
  2. From the Android Studio menu click File > New > Import Project.
    • Alternatively, from the Welcome screen, click Import project (Eclipse ADT, Gradle, etc.).
  3. Select the Eclipse ADT projection folder with the AndroidManifest.xml file and click Ok.

  4. Select the destination folder and click Next.

  5. Select the import options and click Stop.
  6. The import process prompts you to migrate any library and project dependencies to Android Studio, and add together the dependency declarations to the build.gradle file. See Create an Android library for more data nigh this process.

    The import process also replaces any well-known source libraries, binary libraries, and JAR files that have known Maven coordinates with Maven dependencies, and so you no longer need to maintain these dependencies manually. The import options also permit you to enter your workspace directory and whatsoever actual path maps to handle any unresolved relative paths, path variables, and linked resource references.

  7. Android Studio imports the app and displays the project import summary. Review the summary for details about the project restructuring and the import procedure.

After importing the project from Eclipse ADT into Android Studio, each app module folder in Android Studio contains the complete source set for that module, including the src/main/ and src/androidTest/ directories, resources, build file, and Android manifest. Before starting app evolution, you should resolve any issues shown in the project import summary to brand sure the projection re-structuring and import process completed properly.

Import every bit a module:

  1. Beginning Android Studio and open the projection yous'd similar to add together the module to.
  2. From the Android Studio menu click File > New > Import Module.
  3. Select the Eclipse ADT project folder with the AndroidManifest.xml file and click Ok.
  4. Modify the module proper name if desired, and click Next.
  5. The import process prompts you to migrate whatsoever library and project dependencies to Android Studio, and add the dependency declarations to the build.gradle file. For more than about migrating library and project dependencies, see Create an Android library. The import process also replaces any well-known source libraries, binary libraries, and JAR files that have known Maven coordinates with Maven dependencies, so you no longer demand to maintain these dependencies manually. The import options besides allow yous to enter your workspace directory and any actual path maps to handle any unresolved relative paths, path variables, and linked resource references.
  6. Click Terminate.

Validate imported projects

Subsequently completing the import procedure, employ the Android Studio Build and Run menu options to build your projection and verify the output. If your project is not edifice properly, cheque the post-obit settings:

  • Verify the installed versions of your tools friction match the settings for your Eclipse projection by opening the SDK Manager (click the Android SDK Manager button in Android Studio or Tools > SDK Manager). Android Studio inherits the SDK Director and JDK settings from your imported Eclipse projection.
  • To verify additional Android Studio Settings, click File > Project Structure and audit the post-obit:

    • Nether SDK Location verify Android Studio has access to the correct SDK, NDK, and JDK locations and versions.

    Annotation: If you used the default settings, Eclipse ADT installed Android SDK in User\user-name\android-sdks\ on Windows, and in Users/user-name/Library/Android/sdk/ on Mac.

    • Under Projection verify the Gradle version, Android plugin version, and related repositories.
    • Under Modules verify the app and module settings, such as signing configuration and library dependencies.
  • If your project depends on another project, make certain that dependency is defined properly in the build.gradle file in the app module folder. For more information about defining dependencies, run across Configure build variants.

If in that location nonetheless are unexpected issues when building and running your project in Android Studio afterwards yous take checked these settings, consider modifying the Eclipse ADT project and re-starting the import procedure.

Notation: Importing an Eclipse ADT project to Android Studio creates a new Android Studio projection and does not impact the existing Eclipse ADT project.

Migrating from IntelliJ

If your IntelliJ project uses the Gradle build system, you can automatically import your project directly into Android Studio. If your IntelliJ project uses Maven or another build arrangement, you need to gear up it upwardly to work with Gradle before you can drift to Android Studio.

Import a Gradle-based IntelliJ projection

If yous are already using Gradle with your IntelliJ project, yous tin can open it in Android Studio using the following steps:

  1. Click File > New > Import Project.
  2. Select your IntelliJ project directory, and click OK. Your project will open in Android Studio.

Import a non-Gradle IntelliJ project

If your IntelliJ projection does not already use the Gradle build system, you accept ii options for importing your project into Android Studio:

  • Create a new empty Android Studio projection and re-create your existing source code into the directories associated with the new projection. For more information, see Migrate by creating a new empty project.
  • Manually create a new Gradle build file for your project and so import the projection and new build file into Android Studio. For more information see Drift by creating a custom Gradle build file.

Drift past creating a new empty projection

To migrate your project into Android Studio by creating a new empty project and copying your source files into the new directories, proceed as follows:

  1. Open Android Studio, and click File > New > New Projection.
  2. Enter a name for your app project and specify the location where information technology should be created, and so click Next.
  3. Select the grade factors your app will run on, and then click Next.
  4. Click Add No Activity, and so click Finish.
  5. In the Projection tool window, click the arrow to open the view dropdown, and select the Projection view to encounter and explore the organization of your new Android Studio projection. To read more about changing views and how Android Studio structures projects, see Project Files.
  6. Navigate to the location you selected for your new project and move the code, unit tests, instrumentation tests, and resources from your sometime project directories into the correct locations in your new project construction.
  7. In Android Studio, click File > Project Structure to open up the Project Construction dialog. Ensure that your app's module is selected in the left pane.
  8. Make any necessary modifications in the Properties tab for your project (for example, modifying the minSdkVersion or targetSdkVersion).
  9. Click Dependencies and add together whatever libraries your projection depends on as Gradle dependencies. To add a new dependency, click Add together , and so select the type of dependency you would like to add and follow the prompts.
  10. Click OK to save your modifications.
  11. Click Build > Brand Projection to test building your project, and resolve whatever outstanding errors.

Migrate by creating a custom Gradle build file

To drift your project into Android Studio past creating a new Gradle build file to point to your existing source files, keep as follows:

  1. Before you begin, exist sure to back up your project files in a separate location, every bit the migration process will modify the contents of your projection in place.
  2. Next, create a file in your projection directory called build.gradle. The build.gradle file will comprise all the data required for Gradle to run your build.

    Past default, Android Studio expects your project to be organized equally shown in figure 1.

    Effigy 1. The default projection structure for an Android app module.

    Since your IntelliJ project does not apply the same construction, your build.gradle file needs to signal the source directories for the build to your existing folders (for example, res/ and src/) instead of the default new directory construction. The following case build.gradle file includes the basic setup for a Gradle build, besides as a sourceSets{} block inside the android{} block to define the correct source directories and move the tests and build types to avoid naming conflicts. Copy the code block beneath into your build.gradle file and make any changes necessary to work with your existing project setup. For instance, you may have additional dependencies to include, exist using a different target SDK version, or need to specify dissimilar locations for your source directories.

    Groovy

    // This buildscript{} block configures the code driving the build buildscript {    /**     * The nested repositories{} block declares that this build uses the     * jcenter repository.     */     repositories {         jcenter()     }     /**     * This cake declares a dependency on the 7.1.two version     * of the Gradle plugin for the buildscript.     */     dependencies {         classpath 'com.android.tools.build:gradle:7.1.2'     } }  /**  * This line applies the com.android.application plugin. Note that you should  * only apply the com.android.application plugin. Applying the Coffee plugin as  * well volition result in a build error.  */ plugins {   id 'com.android.application' }  /**  * This dependencies block includes any dependencies for the project itself. The  * following line includes all the JAR files in the libs directory.  */ dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])     // Add other library dependencies here (encounter the next step) }  /**  * The android{} block configures all of the parameters for the Android build.  * Yous must provide a value for at least the compilation target.  */ android {     compileSdkVersion 28      /**     * This nested sourceSets cake points the source lawmaking directories to the     * existing folders in the project, instead of using the default new     * arrangement.     */     sourceSets {         main {             manifest.srcFile 'AndroidManifest.xml'             java.srcDirs = ['src']             resource.srcDirs = ['src']             aidl.srcDirs = ['src']             renderscript.srcDirs = ['src']             res.srcDirs = ['res']             assets.srcDirs = ['assets']         }          // Move the tests to tests/java, tests/res, etc...         instrumentTest.setRoot('tests')         /**         * Move the build types to build-types/<type>         * For case, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...         * This moves them out of them default location nether src/<type>/... which would         * conflict with src/ being used by the main source set.         * Adding new build types or production flavors should be accompanied         * by a similar customization.         */         debug.setRoot('build-types/debug')         release.setRoot('build-types/release')      } }

    Kotlin

    // This buildscript{} block configures the code driving the build buildscript {    /**     * The nested repositories{} block declares that this build uses the     * jcenter repository.     */     repositories {         jcenter()     }     /**     * This block declares a dependency on the vii.1.2 version     * of the Gradle plugin for the buildscript.     */     dependencies {         classpath("com.android.tools.build:gradle:vii.ane.2")     } }  /**  * This section applies the com.android.application plugin. Note that you  * should only apply the com.android.awarding plugin. Applying the Java  * plugin likewise will effect in a build fault.  */ plugins {     id("com.android.application") }  /**  * This dependencies cake includes any dependencies for the project itself. The  * following line includes all the JAR files in the libs directory.  */ dependencies {     implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))     // Add other library dependencies here (see the next pace) }  /**  * The android{} block configures all of the parameters for the Android build.  * You must provide a value for at least the compilation target.  */ android {     compileSdkVersion(28)      /**     * This nested sourceSets block points the source code directories to the     * existing folders in the project, instead of using the default new     * organisation.     */     sourceSets {         getByName("main") {             manifest.srcFile("AndroidManifest.xml")             java.srcDirs("src")             resources.srcDirs("src")             aidl.srcDirs("src")             renderscript.srcDirs("src")             res.srcDirs("res")             avails.srcDirs("avails")         }          // Move the tests to tests/java, tests/res, etc...         getByName("instrumentTest").setRoot("tests")         /**         * Move the build types to build-types/<type>         * For case, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...         * This moves them out of them default location under src/<type>/... which would         * conflict with src/ being used past the principal source gear up.         * Calculation new build types or production flavors should be accompanied         * by a like customization.         */         getByName("debug").setRoot('build-types/debug')         getByName("release").setRoot('build-types/release')      } }

    Warning: The JCenter repository became read-but on March 31st, 2021. For more information, run across JCenter service update.

    For more information about setting upwardly and customizing a Gradle build file, read Configure your build.
  3. Next, identify which library projects you are using. With Gradle, you no longer need to add together these libraries as source code projects, you tin refer to them in the dependencies{} block of your build file instead. The build system then handles these libraries for you, including downloading libraries, merging in resource, and merging manifest entries. The following instance adds the declaration statements for Google Play Services and a number of support libraries to the dependencies{} block shown in the instance build file higher up.

    Smashing

    ... dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])      // Google Play Services     compile 'com.google.android.gms:play-services:9.8.0'      // Support Libraries     compile 'com.android.support:appcompat-v7:28.0.0'     compile 'com.android.support:cardview-v7:28.0.0'     compile 'com.android.back up:blueprint:28.0.0'     compile 'com.android.support:gridlayout-v7:28.0.0'     compile 'com.android.back up:leanback-v17:28.0.0'     compile 'com.android.support:mediarouter-v7:28.0.0'     compile 'com.android.support:palette-v7:28.0.0'     compile 'com.android.support:recyclerview-v7:28.0.0'     compile 'com.android.support:support-annotations:28.0.0'     compile 'com.android.support:support-v13:28.0.0'     compile 'com.android.support:back up-v4:28.0.0'      // Note: these libraries require the "Google Repository" and "Android Repository"     //       to be installed via the SDK manager. }

    Kotlin

    ... dependencies {     implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))      // Google Play Services     implementation("com.google.android.gms:play-services:9.8.0")      // Back up Libraries     implementation("com.android.support:appcompat-v7:28.0.0")     implementation("com.android.support:cardview-v7:28.0.0")     implementation("com.android.back up:design:28.0.0")     implementation("com.android.support:gridlayout-v7:28.0.0")     implementation("com.android.support:leanback-v17:28.0.0")     implementation("com.android.support:mediarouter-v7:28.0.0")     implementation("com.android.support:palette-v7:28.0.0")     implementation("com.android.support:recyclerview-v7:28.0.0")     implementation("com.android.support:support-annotations:28.0.0")     implementation("com.android.support:back up-v13:28.0.0")     implementation("com.android.support:support-v4:28.0.0")      // Notation: these libraries require the "Google Repository" and "Android Repository"     //       to be installed via the SDK managing director. }
    For help determining the right declaration statements for your libraries, Gradle, please can provide you with the correct declaration statements based on Maven Primal.
  4. Salve your build.gradle file, and so shut the project in IntelliJ. Navigate to your project directory, and delete the .thought directory and whatsoever .iml files inside your project.
  5. Launch Android Studio, and click File > New > Import Project.
  6. Locate your project directory, click the build.gradle file y'all created above to select it, and so click OK to import your project.
  7. Click Build > Make Project to test your build file by edifice your projection and address whatever errors y'all observe.

Next steps

Once you have migrated your project to Android Studio, learn more about building with Gradle and running your app in Android Studio by reading Build and run your app.

Depending on your projection and workflow, you may as well wish to read more nearly using version control, managing dependencies, signing and packaging your app, or configuring and updating Android Studio. To get started using Android Studio, read Meet Android Studio.

Configure version control

Android Studio supports a variety of version control systems, including Git, GitHub, CVS, Mercurial, Subversion, and Google Cloud Source Repositories.

Afterward importing your app into Android Studio, use the Android Studio VCS menu options to enable VCS support for the desired version control system, create a repository, import the new files into version control, and perform other version command operations:

  1. From the Android Studio VCS bill of fare, click Enable Version Control Integration.
  2. Select a version control system to associate with the project root from the drib down card, then click OK. The VCS menu now displays a number of version control options based on the organization yous selected.

Notation: You can also use the File > Settings > Version Control carte du jour option to set up and modify the version command settings.

For more data about working with Version Command meet IntelliJ Version Control Reference.

Android Back up repository and Google Play Services repository

While Eclipse ADT uses the Android Support Library and Google Play services Library, Android Studio replaces these libraries during the import process with the Android Support Repository and Google Repository to maintain compatible functionality and support new Android features. Android Studio adds these dependencies equally Maven dependencies using the known Maven coordinates, then these dependencies exercise not require transmission updates.

In Eclipse, in order to utilize a Support Library, you must change your project'south classpath dependencies within your development environment for each Back up Library you desire to apply. In Android Studio, yous no longer need to copy library sources into your own projects, y'all can simply declare a dependency and the library is automatically downloaded and merged into your project. This includes automatically merging in resources, manifest entries, ProGuard exclusion rules, and custom lint rules at build fourth dimension. For more than information almost dependencies, see Configure build variants.

App signing

If your app used a debug certificate in Eclipse ADT, Android Studio continues to reference that certificate. Otherwise, the debug configuration uses the Android Studio generated debug keystore, with a known password and a default central with a known password located in $Home/.android/debug.keystore. The debug build type is set to employ this debug configuration automatically when you run or debug your project from Android Studio.

When edifice your app for release, Android Studio applies the release certificate used in Eclipse ADT. If no release certificate was located during the import process, add the release signing configuration to the build.gradle file or employ the Build > Generate Signed APK bill of fare option to open the Generate Signed APK Wizard. For more data about signing your app, see Sign your app.

Adjusting Android Studio's maximum heap size

By default, Android Studio has a maximum heap size of 1280MB. If you lot are working on a large project, or your system has a lot of RAM, you can improve performance by increasing the maximum heap size.

Software updates

Android Studio updates separately from the Gradle plugin, the build tools, and the SDK tools. Y'all can specify which versions you would like to use with Android Studio.

By default, Android Studio provides automated updates whenever a new stable version is released, merely you tin choose to update more frequently and as well receive preview or beta versions.

For more data near updating Android Studio and using preview and beta versions, see Stay updated.