Android Studio added support from Eclipse

Source: Internet
Author: User

Android Studio added support from Eclipse

I have been using Eclipse to develop Android for some years. However, Android Studio (hereinafter referred to AS) is Google's own IDE. Now the AS version 2.0 has been released, and it does have more functions than Eclipse.

AS has high hardware requirements, and Eclipse uses the ADT plug-in for ease of use. This article does not describe the advantages and disadvantages of these two ides. No one can replace them completely and choose what you like.

However, bloggers like to engage in new transactions. AS has been around for so long, it's time to take it out. Added support for the conversion of Android projects that have been developed using Eclipse. (It is to add support for AS. After processing, AS and Eclipse can be used normally, instead of eliminating Eclipse)

The following is a simple example:
1. Create an Android project using Eclipse to ensure normal operation. The project structure is as follows:

2. Right-click the project-> Export-> Android-> Generate Gradle build files-> Next-> Finish

After this operation, the build. gradle file is generated under the project.

At this point, we need to add a local. properties configuration file under the project to specify the sdk directory. The content of local. properties is as follows:

sdk.dir=D\:\\Android\\android-sdk_r10-windows

Alternatively, you can set ANDROID_HOME in environment variables.

3. Run the command to verify whether gradle can be packaged.
First, configure the GRADLE environment variable. Then, enter the current project directory in cmd and run the "gradle clean" command. The required plug-ins and related packages are automatically downloaded from the command line.

If an error occurs in the middle:
FAILURE: Build failed with an exception.

Where:
Build file 'f: \ androidWorkspace \ MyAndroid \ build. gradle' line: 10

What went wrong:
A problem occurred evaluating root project 'myandroid '.

Failed to apply plugin [id 'android']
Gradle version 1.10 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionU
Rl in F: \ androidWorkspace \ MyAndroid \ gradle \ wrapper \ gradle-wrapper.properties to gradle-1.10-all.zip

Check the build. gradle, modify classpath 'com. android. tools. build: gradle: 0.12. + 'is classpath' com. android. tools. build: gradle: 2.0.0-alpha3 'address corresponding to your local gradle version.

After processing this, the problem is solved. You can modify the configuration as needed and try again. Until build successful appears.

4. Package the apk package
Run the command gradle build in the project directory to package the project.
You can specify the-debug or-info parameter to output logs.

After successful execution, the generated apk file is in the build/outputs/apk directory under the project directory. Some reports and other files are stored in the build directory.

By comparing the project structure at the beginning, we found that some files are added to our project. In fact, we can manually copy these files to a new project. The previous one is:

Gradlew (Linux) and gradlew. bat (Windows) are the gradle commands that can be directly executed for us.
For example, in Linux ):
./Gradlew-v to view the version number
./Gradlew clean clear the build folder under the project
./Gradlew build check dependencies and compile and Package <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Examples/examples/cq9u7e + examples/examples + samples + rb2r0ru49sbVzaiwste/z + examples/MHutPKw/LXEz + 7Ev6GjPC9wPg0KPHA + yc/examples/samples + samples/Cw +/ ydLUvavP7sS/tbzI67W9QVPW0MHLPGJyIC8 + large/uxL + 1xMS/large + DQo8aW1nIGFsdD0 = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/160227/041213K54-4.png" title = "\"/>

6. Configure the signature information so that the packaged apk is automatically signed
Android {...} In build. gradle {......} Add signature Configuration:

Android {............ ............ ............ // Signature information signingConfigs {releaseInfo {storeFile file ("shanhy (xiaoshan ). key ") storePassword "xiaoshan" keyAlias "shanhy" keyPassword "xiaoshan" }}buildtypes {// Debug mode debug {}// Release mode release {// whether to enable obfuscation minifyEnabled false // confusion File configure proguardFiles getDefaultProguardFile('proguard-android.txt '), 'proguard-rules. pro' // configure the signature information (if defaultConfig is configured above, you do not need to specify signingConfig) signingConfig signingConfigs. releaseInfo }}

Run the command./gradlew build or./gradlew assemblereluts to view the generated signed apk under build/outputs/apk.

Note: The./gradlew command used in this article is in Linux. If it is in Windows, use gradlew. bat

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.