Summary: How to import a project to Android Studio

Source: Internet
Author: User

The version of Android Studio used in this tutorial is 1.0, Eclipse ADT version 23.0.4. Please try to update to this version.

Android Studio uses Gradle to build projects by default, and Eclipse uses Ant to build projects by default. When you recommend that Android Studio import your project, use Gradle to build your project.

Import Eclipse Project

In this example, the ECLIPSE project structure that is used is shown in the figure:

E-demo main project, APPCOMPAT_V7 for the Library project.

Import Generate Gradle Build Files Project

Google's official recommendation is to use this method to import an Android studio into the Eclipse project.

One advantage of this approach is that it is compatible with Eclipse's file directory structure, through file filtering in version control, and can be used in one project group, with both Eclipse and Android Studio.

Explanation 1

File--> Export

Explanation 2

Select the export type. Select the Android--> Generate gradle build files.

Click Next.

Explanation 3

A long period of English (completely do not understand what meaning).

Click Next.

Explanation 4

Select the project you want to export.

Because my E-demo project relies on the APPCOMPAT_V7 project, I have chosen to export E-demo and appcompat_v7.

Click Next.

Explanation 5

Final confirmation of the project to be exported.

Force overriding of existing files represents overwriting the exported file. Exporting the project using Generate gradle build files will generate some files in the project directory. The overwrite file here refers to overwriting the files that may have been generated. If you have previously exported items in this way, it is advisable to check them.

Click Finish.

Explanation 6

There's nothing to say about this step, just click Finish.

Explanation 7

Finish clicked, there is no pop-up window to display the exported items, as if nothing has been done. In fact, using this method to export a project is to add some files to the project, and we can go down to the project directory and take a look at the generated files.

Working space in the directory

The E-demo directory

The APPCOMPAT_V7 directory

We can find that: in the workspace directory, the Gradle folder and Build.gradle, Build.gradle, Gradlew, Gradlew.bat, settings.gradle files, more than a B in the E-demo directory Uild.gradle documents; The Build.gradle file is more than the APPCOMPAT_V7 directory. These files and folders are related to Gradle and are used to build the project. These files and the role of the folder, we'll say later.

Explanation 8

Since Eclipse's ADT plugin has not been updated for a long time, the auto-generated gradle compilation settings have not been up to date with the Android Studio update, so we need to manually modify some of the content.

Open the Gradle--> wrapper--> gradle-wrapper.properties under the workspace directory. Modify the content: Distributionurl=http://services.gradle.org/distributions/gradle-a.b.c-all.zip--> distributionUrl= Https://services.gradle.org/distributions/gradle-2.2.1-all.zip

Open the Build.gradle file in the workspace directory. Modify the following:

Classpath ' com.android.tools.build:gradle:0.x.+ '--> classpath ' com.android.tools.build:gradle:1.0.0 '.

The reason for this setting is that the Gradle settings exported by Eclipse are no longer supported by the Android Studio 1.0 gradle have Gradle plug-in versions and need to be more supported manually. Otherwise, you must not import the project offline, and the project import fails.

Explanation 9

Open Android Studio and choose Open an existing Android studio project.

Explanation 10

A box pops up and lets you select a folder, and this time you need to be aware that you need to select the original Eclipse workspace directory instead of the E-demo directory.

Click OK.

Explanation 11

Set import options.

Here are some more important settings to explain.

Gradle Project: The path typically shown here is not the directory of your eclipse's workspace, but the Gradle path in the directory of your eclipse's workspace. You need to manually delete the following gradle, otherwise the project import, you can not see your code, only to see the contents of the Gradle directory.

Create directories for empty content roots automatically: not very clear its role, the general default can be.

Use default Gradle wrapper (recommended) and using local Gradle disribution: These two are for you to set the Gradle used. The default will be to check the use default Gradle wrapper (recommended), and we need to manually tick the local gradle disribution.

Gradle Home: This program is editable after the use of local gradle disribution, and the default address here is the Gradle path address in the Android Studio installation directory. There may be some error warning here: Gradle location is incorrect. And your directory, there is indeed a gradle. This problem is most likely due to the Gradle home option, where the slash is/instead of * *. You will need to click on the File Selection button to select the **gradle in the Android Studio installation directory to resolve the problem.

Offline work: Set Gradle to import projects offline. You can either tick or uncheck. If you have an explanation of 8, you can check it out and compile it offline.

Click OK. Then you will see the compilation progress bar, depending on the configuration of each person's machine, compile time is different.

After the compilation is complete, automatically jumps to the main page of Android studio. In the compiled project, there will be the following bomb frame:

The reason for this frame is that the Android studio defaults to JAVA 1.7 for compilation, and if your project is not 1.7, then the frame lets you choose. It is recommended to choose Yes because when you use Java 1.7, you can be perfectly compatible with Java 1.6 's Android devices by not using Java 1.7 resources to automatically release this new feature.

If you see the following interface, it means you have successfully imported it.

Import the Eclipse project directly

If you do not export your project using Generate gradle build files, you can use Android Studio to open the Eclipse workspace directly for project import.

To compile a project without using Gradle

This approach can be compatible with Eclipse's file directory structure, through file filtering in version control, and in one project group, using both Eclipse and Android Studio. But instead of using Gradle to build projects in Android Studio, you use Ant.

Explanation 12

Open Android Studio and select Import non-android Studio project.

In the pop-up directory selection box, select the work space for Eclipse.

Explanation 13

The next step is for you to choose the compilation environment. Select Create Project from existing sources.

Explanation 14

Set up the Android Studio Project name and the storage directory. General default can be.

Click Next.

Explanation 15

Select a resource file and a resource folder. Check the items you want to import. When selecting an item, you need to select the Library project it relies on and his SRC and gen directories.

Select Finish and click Next.

Explanation 16

Select the jar you want to import. The first. Mylyn is the content of the Eclipse plug-in, we need to manually filter it out, and others will choose according to your needs.

Select Finish and click Next.

Explanation 17

Select the Module that Android Studio recognizes, which is Project in Eclipse. Check the items you want to import.

Select Finish and click Next.

Explanation 18

Select the compiled SDK. Here you need to choose the Android SDK, preferably the same SDK you used when you used Eclipse. Again, you can make some simple settings for your environment, and don't say anything about it.

Select Finish and click Next.

Explanation 19

Select the identified Androidmanifest.xml file. The default is all tick.

Click Finish and Android Studio will start importing the project.

Explanation 18

During the import process, if Android Studio recognizes the dependencies of the original project, it pops up a dialog box for you to choose from. If you want to maintain previous dependencies, click OK.

When you see this interface, it means the import is successful. The project uses ANT build, not the default gradle for Android Studio.

Compiling projects using Gradle

One disadvantage of this approach is that only one Eclipse project can be imported at a time. For eclipse projects that use only the official series of support packages, there are many, but also compatible with, the Eclipse file directory structure.

Explanation 19

Open Android Studio and select Import non-android Studio project.

In the pop-up directory selection box, select the directory in which you want to import the item, rather than the Eclipse workspace.

Explanation 20

Android Studio recognizes that your project is an Eclipse Android project that will reuse gradle to build projects.

Android Studio will completely copy the project file into a new directory, and you will need to set the address of this new directory.

When you have finished setting up, click Next.

Explanation 21

Change the previous ANT schema to the Gradle schema.

Replace jars with Dependencies,when possible: Use the ANT's jar dependencies with dependencies refactoring.

Replace Library sources with Dependencies,when possible: Use the dependencies of the ANT Library project dependencies refactoring.

Create Gradle-style (camecase) module names: Use the Gradle style to build the module name for Android Studio.

Recommend all Select, click Finish. Android Studio starts compiling the project and entering the Android Studio home page.

Similarly, in the process of compiling, you will still be prompted with the language level problem, choose Yes.

Import the Android Studio project

The Android Studio project, which is a project built using Gradle. The default file structure is as follows:

Project-name

+ app/

+ src/

+ main/

+ assets/

+ java/

+ Package

...

+ res/

+ drawable/

...

+ Layout

...

+ Values

...

| Androidmanifest.xml

| Build.gradle

+ gradle/

+ wrapper/

| Gradle-wrapper.jar

| Gradle-wrapper.properties

| Build.gradle

| Gradlew

| Gradlew.bat

| Settings.gradle

Some of the Android studio projects have compatibility with Eclipse, and the project structure looks the same as eclipse.

Explanation 22

When you get an Android studio project source from the Web or elsewhere, you want to be able to import it into Android studio. First, you need to make some changes to the source code first. For specific modifications, please refer to the explanation 8.

Open Android Studio and choose Open an existing Android studio project.

In the Pop-up Path selection box, select the Android Studio project you want to import and click OK.

Explanation 23

Then the same page will pop up and explain 11, same, and explain 11 to do the same setting.

After the steps, the same explanation 11, no longer repeat.

Other ways to import

Import a project you can import it from the Android Studio home page, in addition to importing it on the Android Studio starter pages.

File--> import Project or file--> import Module.

The process of the import is the same as the previous explanation, and it is not discussed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.