How to migrate the Eclipse project to Android Studio: eclipseandroid

Source: Internet
Author: User
Tags build gradle

How to migrate the Eclipse project to Android Studio: eclipseandroid

1. Android Studio directly imports the project to copy the original project and cannot be included in code control.

Solution:

Http://developer.android.com/sdk/installing/migrate.html
Translation: Chinese group of Android Studio)

If you have used Eclipse for Android development before and want to import Eclipse projects to the Android Studio environment, you must first generate the Build Gradle file. Because Android Studio uses Gradle to manage projects, the procedure is as follows:

Export from Eclipse

1. Upgrade Your ADT plug-in version to 22.0 or above.
2. In Eclipse, select File --> Export.
3. In the pop-up export window, open the Android folder and select "Generate Gradle Build Files ".
4. Select the project you want to import to Android Studio and Finish.

PS: the exported project will be in the same directory as the original project. When overwriting the original project, a file named build. gradle will be added. When importing the file to Android Studio, the file will be read first.

Import to Android Studio
1. In Android Studio, first turn off your current open project.
2. On the welcome page, click Import Project (Note: You can also select Import project directly from the menu)
3. Select the project you export in Eclipse, expand the directory, click the build. gradle file, and then OK
4. In the subsequent pop-up dialog box, you will be asked to select the Gradle configuration and select Use gradle wrapper. (Note: You can also customize your local Gradle)

PS: If there is no Grade build file, you can also import normal Android projects to Android Studio. It will use the existing Ant build. however, we strongly recommend that you generate a Gradle file from the ADT plug-in before importing the Gradle file to Android Studio.

2. Compilation Error 1

Error: duplicate files during packaging of apk d: \ work \ xxx \ build \ outputs \ apk \ xxx-debug-unaligned.apk
Path in archive: META-INF/LICENSE.txt
Origin 1: D: \ work \ libs \ httpmime-4.1.3.jar
Origin 2: D: \ work \ libs \ ant. jar
You can ignore those files in your build. gradle:
Android {
PackagingOptions {
Exclude 'meta-INF/LICENSE.txt'
}
}
Error: Execution failed for task ': packageDebug '.
> Duplicate files copied in APK META-INF/LICENSE.txt
File 1: D: \ work \ libs \ httpmime-4.1.3.jar
File 2: D: \ work \ libs \ ant. jar
Solution: Add android {} In build. gradle
PackagingOptions {
Exclude 'meta-INF/DEPENDENCIES.txt'
Exclude 'meta-INF/LICENSE.txt'
Exclude 'meta-INF/NOTICE.txt'
Exclude 'meta-INF/notic'
Exclude 'meta-INF/LICENSE'
Exclude 'meta-INF/Dependencies'
Exclude 'meta-INF/notice.txt'
Exclude 'meta-INF/license.txt'
Exclude 'meta-INF/dependencies.txt'
Exclude 'meta-INF/LGPL2.1'
}

3. Compilation Error 2

Importing a project creates a full copy
Error :( 16, 0) Cause: startup failed:
Build file 'd: \ mc_works \ build. gradle ': 16: unexpected char:' \ '@ line 16, column 33.
Java. srcDirs = ['src \ main \ Java']
Solution: Change "\" in gradle to "/"

4. Compilation error 3-unable to compile

Add in Project Master gradle

allprojects {    repositories {        jcenter()    }}

5. Running error-jni lib load failure. jni fails to introduce the project.

Solution: add the following configuration in build. gradle.

sourceSets {    main {
jniLibs.srcDirs = ['libs']

6. The original project root directory contains the jni Directory, which may trigger automatic ndk compilation.

Solution: Add the following red part in gradle to avoid triggering ndk compilation. Set jni. srcDirs to null.

Android {
CompileSdkVersion 19
BuildToolsVersion "23.0.0 rc3"

DefaultConfig {
ApplicationId "com. xxx"
MinSdkVersion 15
TargetSdkVersion 19
SourceSets. main {
Jni. srcDirs = []
JniLibs. srcDir 'src/main/libs'
}

.....


}

Shortcut Keys can be set to eclipse habits (or some shortcut keys are different ):




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.