This is an application for technology developers, you can get the latest and best technical dry products in the Nuggets, not only Android knowledge, front end, back end so that the product and design are covered, want to be a friend of the whole stack of engineers do not miss!
When it comes to using Android studio, in addition to the new project, we are faced with the question of how the original eclipse code should be imported into Android studio.
This aspect of the relevant information is relatively small, his own groping a bit, summed up this blog, hoping to allow developers to take a few detours.
OK, get to the chase.
Google provides two ways to import Eclipse code in order to make it easier for us to use Androidstudio: one compatible with Eclipse, and the new Android Gradle Project.
Here, let's start with the compatibility model.
Compatibility mode
This model ensures that the code directory structure of the Eclipse era is the same as the overall operation and use of Eclipse.
Most importantly, when you use Androidstudio, you or someone else can easily use eclipse and not interfere with each other.
Implement Step 1. Export Gradle build files from eclipse
In the Eclipse menu, File--export-->generate Gradle build files
Next you will arrive at the warning screen, where you will be prompted to Androidstudio directly into the project of ADT, preceded by a direct import explanation.
Select your project engineering, including the main engineering and Library project (library).
Confirm Build
2. Modify the Export file parameters
After the export, because ADT has not been updated for a long time, need to manually change some parameters to ensure normal use.
In order to be able to explain the clearer, the following sub-conditions to explain:
There is no library project, only the main project
In this case the directory you see is like this
The first thing to change is the Build.gradle file
Androidstudio 1.0 ~ 1.0.2 use Android Gradle plugin 1.0.0, so you need to change the 0.12.+ in the red box in the diagram to 1.0.0
You will then need to update the Gradle version to specify the required 2.2.1
Inside the/gradle/wrapper/gradle-wrapper.properties.
Contains library engineering
In fact, the change method is the same as above, only need to pay attention to change the whole project Build.gradle and/gradle/wrapper/gradle-wrapper.properties.
Instead of trying to find Build.gradle in the main engineering or library project.
3. Import Androidstudio
Enter into Androidstudio, select Import Non-Androidstudio project
Locate the project catalog that you want to import, and you can see that the icon is different from the project created by Eclipse.
Click OK to enter the lengthy loading process, then you can use it normally.
Open Androidstudio that have already been created will go directly to the previous project
You can choose File-->import Project at this time, click OK after selecting
Bug in Compatibility mode
Using the IDE's packaging:
In compatibility mode only hit the main project, the library project is not added to the apk, resulting in a non-functional operation.
This bug still exists until 1.0.2,androidstudio.
Because of the presence of this bug, you can use Androidstudio programming in compatibility mode to turn on Eclipse when you pack.
OK, the compatibility mode is introduced here. We begin to introduce the protagonist: Android Gradle Project. It's important to note that Google wants us to use this approach, and if there is no pressure on the team, use it.
Transforming the directory structure with a new directory structure
-
Open import
-
Directly find the original Eclipse project
-
A single project can be imported directly.
-
There is a need for library engineering to be aware that the import must point to the main project, not the entire project's directory. Pointing to the project directory is not possible for conversion.
-
Specify a destination path
-
This place needs to be detailed.
Here are two options for the moment, tick the box.
The last item to mention: Create the module name as a CamelCase style.
Hump style, this Java will be familiar, CamelCase represents the first letter lowercase camel style, CamelCase represents the first capital of the camel style.
Do not check this option means that your original project name is what kind of, converted is what kind.
The Androidstudio here will analyze the. project file under Eclipse Engineering, where the name is the project name you see in Eclipse. (The folder name for this project will be used when this file is not available.)
Of course there are exceptions, such as countly-sdk-android conversion is finished countlysdkandroid, underline I do not know, this did not study the rules carefully, but CamelCase will remain normal.
Here I prefer the first letter of the module (I do not know why look at the first letter lowercase uncomfortable), the original project is CamelCase style, I do not tick.
Of course, if there is no notice here directly converted to CamelCase but finally do not like to do? You can see the section on how to change the module name later.
OK, click Finish after configuration
A period of conversion is required after the
-
. After success can see Import-summary.txt, this file is very useful, will be discussed later.
Here, your application can actually be compiled by Androidstudio, you can also write code to go.
But I hope you can keep on watching, because the import-summary.txt that came out after the success wrote something very important.
Take you to understand import-summary.txtmanifest merging
Your Project uses libraries that provide manifests, and Your Eclipse
Project did not explicitly turn on manifest merging. In Android Gradle
Projects, manifests is always merged (meaning. Contents from your
Libraries ' manifests'll be merged into the app manifest. If you had
Manually copied contents from the library manifests into your app manifest
Need to remove these for the app to build correctly.
This paragraph should be able to read, nothing more than to say that your library's inventory file is valid.
Do not manually copy to the main project manifest file. Previously copied, to be removed in order to build correctly.
Ignored Files (this most important)
This is partly important because Androidstudio tells you through this text that it ignores which files when it is imported.
In other words, this part of the content, it did not cuff you in, if you do not copy yourself, then this part of your new Gradle project there is no.
Here are some typical ignore files to look at:
123456789101112 |
From SDK: * proguard-project.txt * proguard.cfg From UI: * cert\ * cert\cert From CrosswalkWebview: * ant.properties * build.xml From SlidingMenuLibrary: * LICENSE.txt * pom.xml |
To classify the above ignored files:
Really unwanted: Confusing files, Ant's Ant.properties and Build.xml, Maven's pom.xml.
Need to re-declare: LICENSE.txt. Do not declare a piracy infringement AH ~ ~
Custom folders and files: Cert. This folder was created by itself and does not belong to the Android-defined directory, so Androidstudio did not give copies.
Be aware of your ignored files section and manually copy them to the new project according to your needs.
Replaced Jars with Dependencies & replaced Libraries with Dependencies
In the replaced Jars with Dependencies section, the following text is available:
123 |
android-support-v4.jar => com.android.support:support-v4:21.0.3 gson-2.3.jar => com.google.code.gson:gson:2.3 joda-time-2.6.jar => joda-time:joda-time:2.6 |
You can see that the jar is replaced. You can see that there are no jar packages added to the project. So where's the jar bag?
Let's leave a suspense for the time being.
We continue to see replaced Libraries with dependencies part
123 |
ActionbarLibrary => com.actionbarsherlock:actionbarsherlock:[email protected] com.android.support:support-v4:21.0.3 |
You can see that actionbarsherlock is substituted for AAR (Android ARchive, Jar:java ARchive). The introduction of AAR can be seen here, this article is no longer detailed.
You can see that the library and jar have been replaced, but you will never find it in the current project. Why is this?
Let me see the following actions:
Right-click on module and select Open Module Settings
Switch to Dependencies
Click the plus sign on the right to add, select Library dependency
You can see this interface:
OK, here you can know the truth, in the androidstudio you can add the online library or jar package, after the addition of the completion you can and normal use as usual.
Your colleagues will be able to download the project in real time and make sure that your code is working properly.
That's why some jars and libraries disappear after your project has been converted. They were turned into the online.
Moved Files
This section tells you the structure of your directory changes, basically can think of him in nonsense, nothing to see the need for.
Next Steps & Bugs
Oh, skip it.
One last sentence
This import summary are for your information only, and can be deleted
After import once is satisfied with the results.
Once you feel that your project is fine, you can delete the file.
Import Androidstudio Engineering Note
With the above steps, your project has transformed the directory structure, and you can submit the code for other colleagues to download and use.
Other colleagues to download the code, they need to introduce an Android Gradle project.
It is important to note that for projects that contain library projects, you need to specify the entire project directory, and it is useless to specify the main project alone.
Here we need to stop to sum up:
If you are importing an Eclipse project, specify the main project directory. Androidstudio through the analysis to help you complete the conversion.
If you are importing a Androidstudio project, specify the directory for the entire project.
Attached: How to change the module name
On the module right-refactor--> Rename, of course, you can see the shortcut key SHIFT + F6, so you can change the module name.
But it's not over yet, so there's no change in where this module is referenced.
If he is a library project, you also need to continue to see where it is referenced and make changes. It is mainly the Gradle file of other module.
Tips:
Select Module,ctrl+c to copy the project name and replace Ctrl + V with the new name in the relevant Gradle file.
Finally, don't forget, Settings.gradle, the module name of the include here also needs to be changed. This is the end of the modification.
After all the changes have been made, click on Sync now in the pop-up prompt to get the project rebuilt
After the build is over, everything is fine.
Of course, if you look at the name of the folder is not pleasing to the eye, you can also go to modify the folder name, change, remember to re-import.
Summarize
The above is the introduction of two ways to import, in general, the first suitable for frustration in advance familiar with the Android Studio, the second is the more recommended way.
Whichever you do, you'll want to get in touch with Android Studio as quickly as you can and experience its power.
Reprinted from: Gavinct
(forward) Two ways to import your eclipse code into Android Studio