Several ways to import projects from 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 that version.

Android Studio uses Gradle to build projects by default, and Eclipse uses Ant to build projects by default. It is recommended that Android studio build the project using Gradle when importing the project.

Import Eclipse Project

In this example, the Eclipse project structure used

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

Import generate Gradle Build files project

Google's official recommendation is to import the Eclipse project into Android Studio through this method.

One benefit of this approach is that it is compatible with the Eclipse 's file directory structure, which is filtered by file in version control and can be used in a project group with Eclipse and Android Studio.

Explanation 1

file--> Export

Explanation 2

Select the export type. Select Android -- Generate Gradle build Files .

Click Next .

Explanation 3

A long period of English (completely don't understand what it means).

Click Next .

Explanation 4

Select the items you want to export.

Because my E-demo project relies on the appcompat_v7 project, I've chosen to export both E-demo and appcompat_v7 .

Click Next .

Explanation 5

Finalize the project that you want to export.

Force overriding of existing files means overwriting the export file. By exporting the project using Generate Gradle build files, some files are generated 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 recommended to tick.

Click Finish .

Explanation 6

This step is nothing to say, just click Finish .

Explanation 7

Finish clicked, and no pop-up window shows the exported item as if nothing had been done. In fact, using this method to export the project, is to add some files in the project, we can go to the project directory to look at these build files.

Working Space Directory

Under the E-demo directory

Under the APPCOMPAT_V7 directory

We can find: in the workspace directory, the gradle folder and build.gradle ,build.gradle , gradlew , Gradlew.bat , settings.gradle file; build.gradle file in e-demo directory; in appcompat_v7 the build.gradle file is more than the 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 will talk about 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 keeping up with the update speed of Android studio. So we need to manually modify some of the content.

Open the workspace directory gradle -- wrapper --and gradle-wrapper.properties . 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 under the workspace directory. Modify the following content:

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

This is set because the Gradle settings that Eclipse exported are not already Gradle plug-in versions supported by Android Studio 1.0 and need to be The version 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 will pop up to allow you to select a folder, so it's important to note 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 that is 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 will be imported, you can not see your code, only see the contents of the gradle directory.
  • Create directories for empty content roots automatically: not very clear about its role, the general default can be.
  • Using default Gradle wrapper (recommended) and use local gradle disribution: These are the gradle that let you set the usage. By default, the use default Gradle wrapper (recommended) is checked, and we need to manually tick the local gradle disribution .
  • Gradle Home : Check the use local Gradle disribution after this program editable state, the default address here is the Android Studio installation directory of Gradle The path address. There may be some false warnings, as follows: Gradle is incorrect . And you have this directory, there is indeed a Gradle . The cause of this problem is most likely due to the Gradle home option, where the slash in the path is / rather than * *. You need to click the left and right file selection button and re-select the **gradle in the Android Studio installation directory to resolve the issue.
  • Offline work: Set up Gradle to import items using offline mode. You can check it or uncheck it. If you have an operation that explains 8 , you can check it out and compile it offline.

Click OK . After that you will see the compilation progress bar, depending on the configuration of each machine, the compilation time is different.

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

The reason for this frame is that Android Studio is compiled by default with JAVA 1.7 , and if your project is not 1.7 , the box will let you choose. It is recommended that you choose Yes , because when you use Java 1.7 , you can be perfectly compatible with Java 1.6 Android devices as long as you do not use Java 1.7 resources to automatically release this new feature.

If you see the following interface, you have already imported the success.

Import an 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.

Compiling a project without using Gradle

This way can be compatible Eclipse with the file directory structure, through version control file filtering, can be in a project group, while using Eclipse and Android Studio. But instead of using Gradle to build a project in Android studio, you're using Ant .

Explanation 12

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

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

Explanation 13

Next, let you choose the compilation environment. Select Create Project from existing sources .

Explanation 14

Set the Android Studio Project name and store the directory. General default.

Click Next .

Explanation 15

Select the resource file and the resource folder. Tick based on the items you need to import. When selecting a project, you need to select the Library project It depends on and his src and gen directories.

Select Finish, click Next .

Explanation 16

Select the jar to import. The first . Mylyn is the content of the Eclipse plugin, which we need to filter manually, and others to choose according to your needs.

Select Finish, click Next .

Explanation 17

Select the Module identified by Android Studio, which is Project in Eclipse . Tick the items you want to import.

Select Finish, click Next .

Explanation 18

Select the compiled SDK . Here, you need to choose the Android SDK , preferably the same SDK you used when using Eclipse . Again, you can do some simple environment setup again, not here.

Select Finish, click Next .

Explanation 19

Select the identified androidmanifest.xml file. The default is to check all the options.

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, a dialog box pops up to let you choose. If you want to keep the previous dependencies, click OK .

When you see this interface, it means that the import was successful. The project is built using Ant and is not the default Gradle of Android Studio.

Compiling a project using Gradle

One drawback of this approach is that you can import only one Eclipse project at a time. For Eclipse projects that use only the official series of support packages, there are a number of aspects that are 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 where you want to import the project, not the Eclipse workspace.

Explanation 20

Android Studio recognizes that your project is an Eclipse Android Project and it will re-use Gradle to build the project.

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

Setup is complete, click Next .

Explanation 21

Change the previous Ant schema to the Gradle schema.

    • Replace jars with dependencies,when possible : Use dependencies refactoring with Ant 's jar dependencies.
    • Replace Library sources with Dependencies,when possible: Use the dependencies of the Ant Library Project dependencies refactoring.
    • Create Gradle-style (camecase) module names : Build the module name for Android studio using the Gradle style.

Select All, click Finish . Android Studio starts compiling the project and goes to the Android Studio home page.

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

Import an Android Studio project

The Android Studio project refers to a project that was 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 Android studio projects have compatibility with Eclipse , and the project structure looks the same as Eclipse .

Explanation 22

When you get a copy of the Android Studio project source from the Web or elsewhere, you want to be able to import into Android studio. First, you need to make some changes to this source code. For specific changes, please refer to the Explanations in section 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 it will pop up and explain the same page, and the same, and explain the same settings.

Several ways to import projects from Android Studio

Related Article

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.