How to create a new Build.gradle?

4

Since I imported my gitHub project, I'm trying this error:

  

Migrate Project to Gradle? This project does not use the Gradle build system. We recommend that you migrate to the Gradle build system

One guy already told me that I need to create a build.gradle to add to the project, but I do not know how to do it. Can someone help me?

    
asked by anonymous 03.11.2015 / 17:11

1 answer

1

TL; DR

The message is of recommendation, not obligation, but it is worth using Gradle in the project.

Gradle

Gradle is a build automation tool, that is, processes that involve your code for compilation, packaging, testing and distribution.

A project that uses Gradle must have at least one build.gradle file with the necessary settings.

IDEs such as Eclipse and IntelliJ, the latter the basis of Android Studio , make use of the Gradle configuration for some automatic settings, although it is perfectly possible to perform these settings manually, that is, without Gradle.

Gradle is usually recommended for Android development rather than manual configuration, because it greatly facilitates development and standardizes the procedures for compiling and distributing the project.

Simple setup example

A documentation gives an example of a simple setup for an Android project:

buildscript {
    repositories { 
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.1.0'
}

Build Init Plugin

For some common project types, there is a Gradle plugin that allows you to generate the basic configuration: Build Init Plugin . For example, if you have Gradle installed you can run the following command line:

gradle init --type java-library

The basic configuration will be created according to the project type ( type ). However, this plugin is still in the process of incubation and still has no option for an Android project. Also, the configuration is basic and most likely more specific changes will be needed.

Of course, each project can have different settings and you will probably need to go through the documentation a bit to get all the details.

Considerations

Build automation is something that can give you a headache at first, especially the first time you do it, but it's something you pay for over time.

At this point, a few times you can rely on IDEs or tools to generate a basic configuration, but I do not recommend relying on it or always following it. It's best to take a little time to understand the basics of how Gradle works.

    
17.12.2015 / 01:17