Migrating your projects to Android Studio requires adapting to a new project structure, build system, and IDE functionality. If you 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 information, 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 you are using IntelliJ, but your project does not already use Gradle, you will need to do a little bit of manual preparation before you can import your project into Android Studio. For more information, see Migrating from IntelliJ.
Here are some of the key differences you should be aware of as you prepare to migrate to Android Studio.
Android Studio is based on the IntelliJ IDEA IDE. To become familiar with the IDE basics, such as navigation, code completion, and keyboard shortcuts, see Meet Android Studio.
Android Studio does not use workspaces, so separate projects open 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 project contains one or more modules, which allow you to divide your project into discrete units of functionality. Modules can be independently built, tested, and debugged.
For more information about Android Studio projects and modules, see the Projects Overview.
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 significant features for Android development, including the following:
For more information about using and configuring Gradle, see Configure Your Build.
Library dependencies in Android Studio use Gradle dependency declarations and Maven dependencies for well-known local source and binary libraries with Maven coordinates. For more information see, Configure Build Variants.
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 project's main
sourceset so you can easily add and maintain your instrumentation test code
within the same project view. Android Studio also provides a test/
directory in
your project's main sourceset for local JVM tests.
Android Studio offers an automated import tool for existing Android projects created using Eclipse.
Before migrating your app from Eclipse to Android Studio, review the following steps to make sure your project is ready for conversion, and verify you have the tool configuration you need in Android Studio:
AndroidManifest.xml
file. Also, the root directory must contain either the .project
and
.classpath
files from Eclipse or the res/
and src/
directories.project.properties
or.classpath
files for import. You can add these
references in the build.gradle
file after the import. For more information,
see Configure Your Build.You should decide how you will import your existing Eclipse ADT projects depending on their structure:
AndroidManifest.xml
file
and click Ok.
The import process prompts you to migrate any library and project
dependencies to Android Studio, and add the dependency declarations to the
build.gradle
file. See
Create an Android Library for
more information about 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, so you no longer need to maintain these dependencies manually. The import options also allow you to enter your workspace directory and any actual path maps to handle any unresolved relative paths, path variables, and linked resource references.
Android Studio imports the app and displays the project import summary. Review the summary for details about the project restructuring and the import process.
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 development, you should
resolve any issues shown in the project import summary to make sure the project
re-structuring and import process completed properly.
AndroidManifest.xml
file
and click Ok.build.gradle
file. For more 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 need to maintain these dependencies manually.
The import options also allow you to enter your workspace directory and any
actual path maps to handle any unresolved relative paths, path variables, and
linked resource references.After completing the import process, use the Android Studio Build and Run menu options to build your project and verify the output. If your project is not building properly, check the following settings:
To verify additional Android Studio Settings, click File > Project Structure and inspect the following:
Note: If you used the default settings,
Eclipse ADT installed Android SDK in
User\user-namendroid-sdks\
on Windows, and in
Users/user-name/Library/Android/sdk/
on Mac.
build.gradle
file in the app module folder. For more
information about defining dependencies, see
Configure Build Variants.If there still are unexpected issues when building and running your project in Android Studio after you have checked these settings, consider modifying the Eclipse ADT project and re-starting the import process.
Note: Importing an Eclipse ADT project to Android Studio creates a new Android Studio project and does not impact the existing Eclipse ADT project.
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 system, you need to set it up to work with Gradle before you can migrate to Android Studio.
If you are already using Gradle with your IntelliJ project, you can open it in Android Studio using the following steps:
If your IntelliJ project does not already use the Gradle build system, you have two options for importing your project into Android Studio:
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:
minSdkVersion
or
targetSdkVersion
).
To migrate your project into Android Studio by creating a new Gradle build file to point to your existing source files, proceed as follows:
build.gradle
. The build.gradle
file will contain all
the information required for Gradle to run your build.
By default, Android Studio expects your project to be organized as shown in figure 1.
Figure 1. The default project structure for an Android app module.
Since your IntelliJ project does not use the same structure, yourbuild.gradle
file needs to point the source directories for the
build to your existing folders (for example, res/
and
src/
) instead of the default new directory structure.
The following example build.gradle
file includes the basic
setup for a Gradle build, as well 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
below into your build.gradle
file and make any changes
necessary to work with your existing project setup. For example, you may have
additional dependencies to include, be using a different target SDK version,
or need to specify different locations for your source directories.
// 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 2.2.0 version * of the Gradle plugin for the buildscript. */ dependencies { classpath 'com.android.tools.build:gradle:2.2.0' } } /** * This line applies the com.android.application plugin. Note that you should * only apply the com.android.application plugin. Applying the Java plugin as * well will result in a build error. */ apply plugin: '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 (see the next step) } /** * The android{} block configures all of the parameters for the Android build. * You must provide values for at least the build tools version and the * compilation target. */ android { compileSdkVersion 25 buildToolsVersion "25.0.0" /** * This nested sourceSets block points the source code directories to the * existing folders in the project, instead of using the default new * organization. */ sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.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 instance, 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 by the main source set. * Adding new build types or product flavors should be accompanied * by a similar customization. */ debug.setRoot('build-types/debug') release.setRoot('build-types/release') } }For more information about setting up and customizing a Gradle build file, read Configure Your Build.
dependencies{}
block of your build file instead. The build
system then handles these libraries for you, including downloading libraries,
merging in resources, and merging manifest entries. The following example adds
the declaration statements for Google Play Services and a number of support
libraries to the dependencies{}
block shown in the example build
file above.
... 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:25.1.0' compile 'com.android.support:cardview-v7:25.1.0' compile 'com.android.support:design:25.1.0' compile 'com.android.support:gridlayout-v7:25.1.0' compile 'com.android.support:leanback-v17:25.1.0' compile 'com.android.support:mediarouter-v7:25.1.0' compile 'com.android.support:palette-v7:25.1.0' compile 'com.android.support:recyclerview-v7:25.1.0' compile 'com.android.support:support-annotations:25.1.0' compile 'com.android.support:support-v13:25.1.0' compile 'com.android.support:support-v4:25.1.0' // Note: these libraries require the "Google Repository" and "Android Repository" // to be installed via the SDK manager. }For help determining the correct declaration statements for your libraries, Gradle, please can provide you with the correct declaration statements based on Maven Central.
build.gradle
file, then close the project in
IntelliJ. Navigate to your project directory, and delete the
.idea
directory and any .iml
files inside your
project.build.gradle
file you
created above to select it, and then click OK to import your
project.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 project and workflow, you may also wish to read more about 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.
Android Studio supports a variety of version control systems, including Git, GitHub, CVS, Mercurial, Subversion, and Google Cloud Source Repositories.
After 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 control operations:
Note: You can also use the File > Settings > Version Control menu option to set up and modify the version control settings.
For more information about working with Version Control see IntelliJ Version Control Reference.
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 as Maven dependencies using the known Maven coordinates, so these dependencies do not require manual updates.
In Eclipse, in order to use a Support Library, you must modify your project's classpath dependencies within your development environment for each Support Library you want to use. In Android Studio, you no longer need to copy library sources into your own projects, you 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 time. For more information about dependencies, see Configure Build Variants.
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
key with a known password located in $HOME/.android/debug.keystore
. The debug
build type is set to use this debug configuration automatically when you run
or debug your project from Android Studio.
When building 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 use the Build > Generate Signed APK menu option to open the
Generate Signed APK Wizard. For more information about signing your app, see
Signing Your Applications.
By default, Android Studio has a maximum heap size of 1280MB. If you are working on a large project, or your system has a lot of RAM, you can improve performance by increasing the maximum heap size in the VM options for Android Studio.
For more information about configuring Android Studio settings, see Configure Android Studio and Configuring Android Studio.
Introduced in Android Studio 2.0, Instant Run is a behavior for the Run and Debug commands that significantly reduces the time between updates to your app. Although your first build may take longer to complete, Instant Run pushes subsequent updates to your app without building a new APK, so changes are visible much more quickly. You can improve the build process for Instant Run by changing a few Android Studio settings.
For more information about configuring your project for Instant Run performance, see Configure and optimize your project for Instant Run.
Android Studio updates separately from the Gradle plugin, the build tools, and the SDK tools. You can specify which versions you would like to use with Android Studio.
By default, Android Studio provides automatic updates whenever a new stable version is released, but you can choose to update more frequently and also receive preview or beta versions.
For more information about updating Android Studio and using preview and beta versions, see Stay Updated.