Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set gradle properties for all my android projects?

How to set gradle properties for all my android projects? I have diffrent android projetcs but whenever i change my gradel.properties file in project folder it only affect that projects. And i cannot find the gradle.properties in .gradle folder in root directory. How do i set common properties for all projects so i dont need to change everytime.

like image 750
Amit Kumar Avatar asked Jul 24 '18 10:07

Amit Kumar


People also ask

Where is gradle properties in Android?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project.

How do I sync gradle with Android project?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.


4 Answers

Gradle supports system-wide properties in a gradle.properties file in the GRADLE_USER_HOME directory, which defaults to a folder called .gradle in your home directory, e.g. C:\Users\<user>\.gradle on Windows.

These system specific properties may override project specific properties, so they can be used to specify usernames and passwords only for your local machine.

This global gradle.properties may not exist by default, but even if not, you can create one and it will be used and the properties will be available in your build script.

If your global settings require more logic than just plain properties, you can use initialization scripts, which can be placed in the same location (or the init.d subdirectory).

like image 70
Lukas Körfer Avatar answered Nov 15 '22 05:11

Lukas Körfer


For MacOS users:

  1. Open terminal and enter cd ~/.gradle
  2. Do a ls to check whether gradle.properties already exists or not
  3. If it doesn't exist, create one: vi gradle.properties.
  4. If it exists, just modify the configs you want to modify and save it.
like image 20
div Avatar answered Nov 15 '22 05:11

div


Here is the answer

This global gradle.properties may not exist by default, but even if not, you can create one and it will be used and the properties will be available in your build script.

Create one in C:\Users\user-name.gradle and name it gradle.properties without any extensions.

like image 28
Safa Avatar answered Nov 15 '22 06:11

Safa


Documentation :

Project properties are inherited from parent to child projects.

Root Project

ext{
    supportLibVersion = '25.3.1'

    //supportLib
    supportLib = "com.android.support:support-v4:$supportLibVersion"
}

Child Projects:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    //supportLib
    compile rootProject.ext.supportLib
}
like image 21
Ravindra Shekhawat Avatar answered Nov 15 '22 05:11

Ravindra Shekhawat