Build Android Apps with Gradle

Source: Internet
Author: User

Introduction:because Android Studio uses the Build tool Gradle, if Eclipse and Android studio want to build each other's apps, you must use Gradle. Gradle is based on the Groovy language and is oriented toward Java applications. Automated building tools based on DSL (domain-specific language) syntax. Home: http://www.gradle.org/Note: 1, because Android uses the Gradle version is 1.12, so download 1.12 version, using the high version will be an error. 2. When you export gradle.build in eclipse, if there are some dependencies error: Make sure all dependencies is opened, you want to ensure that the location of the dependency is the same as the project in workspace! Settings: 1, after downloading the gradle, you need to set the system environment variables,variable Name: Gradle_home variable Value: Your path \gradle-1.12,then add%gradle_home%\bin in the system variable path;2, also note that the Android environment variable is set, variable name:Android_homeVariable Value: The path to the ANDROIDSDK (for exampleE:\Program Files (x86) \ANDROID\ANDROID-STUDIO\SDK),then add in the system variable path%android_home%\tools; Example: Android samples are mostly built with Gradle after Android-18, so it's a hassle to look at the example apk build with Eclipse. Suppose I now want to build the Sdk\samples\android-19\ui\customnotifications apk view example directly. Directory structure Open cmd--"CD sample Directory-" Run Gradle build when you are finished seeing build success or in Customnotificationssample\build\outputs\ The APK folder to see that the build was successful. Let's try another example \sdk\samples\android-20\ui\textswitcher, is the step gradle so magical? Will the app be built automatically? In fact, in the process of construction, the use of build.gradle this file, the content is to build the script
  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath ‘com.android.tools.build:gradle:0.10.+‘
  7. }
  8. }
  9. apply plugin:‘android‘
  10. dependencies {
  11. // Add the support lib that is appropriate for SDK 4
  12. compile "com.android.support:support-v4:19.1.+"
  13. }
  14. // The sample build uses multiple directories to
  15. // keep boilerplate and common code separate from
  16. // the main sample code.
  17. List<String> dirs =[
  18. ‘main‘,// main sample code; look here for the interesting stuff.
  19. ‘common‘,// components that are reused by multiple samples
  20. ‘template‘]// boilerplate code that is generated by the sample template process
  21. android {
  22. compileSdkVersion 19
  23. buildToolsVersion "19.0.1"
  24. sourceSets {
  25. main {
  26. dirs.each { dir ->
  27. java.srcDirs "src/${dir}/java"
  28. res.srcDirs "src/${dir}/res"
  29. }
  30. }
  31. androidTest.setRoot(‘tests‘)
  32. androidTest.java.srcDirs =[‘tests/src‘]
  33. }
  34. }
In general, we use auto-generatedBuild.gradleOf course you can also write your own handwriting, but the premise is to go to the official website to learn relevant content.  when Eclipse ADT is upgraded to version 22.0 or higher, we can use the exported Androidbuild.gradle function.
Follow the steps to go. In Android studio, import thisBuild.gradle can import the Eclipse project into Android Studio.



From for notes (Wiz)



Build Android Apps with Gradle

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.