Android project added support from Eclipse Android Studio

Source: Internet
Author: User

Using Eclipse to develop Android has been around for some years, but Android Studio (hereafter abbreviated as) is Google's own push IDE. As is now in its 2.0 version, it does have more functionality than eclipse.

As is a high-hardware requirement, Eclipse uses ADT plug-ins to be easy to use. This article does not explain the advantages and disadvantages of the 2 Ides, no one can completely replace which of the said, choose their favorite is good.

But bloggers like to get in touch with new business, as it's been so long, it's time to take it out for a walk. For Android projects that have been developed using eclipse, how to convert add support as. (is to increase support for as, after processing as and eclipse can be used normally, rather than to waste eclipse)

Here's a simple example that shows you the following steps:
1. Create an Android project with Eclipse to make sure it works. The project structure is as follows:

2, right-click Project, export-> android-> Generate Gradle build files-> next-> next-> Finish

When you do this, the Build.gradle file is generated under the project.

At this point, we also need to add a local.properties configuration file under the project, specify the SDK directory, local.properties content as follows:

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

Or you can set android_home in the environment variable.

3. At this point we use the command to verify if we can use Gradle packaging.
The first step is to configure the GRADLE environment variable. Then enter the current project directory in cmd, execute the command "Gradle clean", and the command line will see the required plugins and related packages to be downloaded automatically.

If there is an error 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

Then check build.gradle, modify Classpath ' com.android.tools.build:gradle:0.12.+ ' to Classpath ' Com.android.tools.build:gradle : 2.0.0-alpha3 ' address corresponding to your local gradle version.

After I have dealt with this problem, we have to modify the configuration according to their own situation and then try again. Until the BUILD successful appears.

4. Pack APK Package
Execute the command under the project directory: Gradle build to package the project.
You can specify the –debug or –info parameter output log.

After successful execution, the generated apk file is in the build/outputs/apk directory under the project directory. The build directory contains some files such as reports.

Comparing the structure of the project we started with, we found that some files were added to our project, and we can actually copy the files to a new project by hand, the last one:

where Gradlew (Linux) and Gradlew.bat (Windows) are the Gradle commands generated for us that can be executed directly.
such as (under Linux):
./gradlew-v View Version number
./gradlew Clean Cleanup Project under the build folder
./gradlew build check dependencies and compile package

Note Using build packaging will release the debug, Release environment package, if the formal environment only need to package release, please use the following command:
./gradlew Assembledebug compiles and hits the debug package
./gradlew Assemblerelease compiling and playing the release package
./gradlew installrelease Release mode compile and install
./gradlew uninstallrelease Uninstall Release installation package

So far, we've turned a common Android project into a project that supports Gradle command packaging.

There's so much to say, just to let you know how to use Gradle to pack the APK instead of just moving to as.

5, the following can be imported into as the project
Select File-> Open in AS and select the directory of our project (for example: F:\androidWorkspace\MyAndroid), and then wait a while.

Finally, the project after importing as:

6, configure the signature information, so that after the packaged apk automatic signature
Add a signature configuration to Android {...} in Build.gradle:

Android{........ ....................//Signature informationsigningconfigs{Releaseinfo {StoreFilefile("Shanhy (Xiaoshan). Key") Storepassword"Xiaoshan"Keyalias"Shanhy"Keypassword"Xiaoshan"}} buildtypes {//debug ModeDebug {}//release ModeRelease {//Whether to enable obfuscationMinifyenabledfalse           //Confusing file configurationProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '           //Signature information configuration (if Defaultconfig is configured above, you can not specify Signingconfig)Signingconfig Signingconfigs.releaseinfo}}

Executes the command./gradlew build or./gradlew assemblerelease to see the generated signed apk under BUILD/OUTPUTS/APK

Note: the./gradlew used in this article is a command under Linux, and if under Windows, use Gradlew.bat

Android project added support from Eclipse Android Studio

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.