Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get acces to values from another gradle file?

Ok, here is my current build.gradle:

apply plugin: 'com.android.application'
apply from: '../config.gradle'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
       applicationId ""
       minSdkVersion 15
       targetSdkVersion 21
       versionCode 1
       versionName "1.0"
    }
    buildTypes {
        release {
        resValue "int", "amountOfTables", amountOfTables
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    howManyTables.execute()
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.pnikosis:materialish-progress:1.4'
}

and that's the config.gradle:

def amountOfTables = 15

task howManyTables << {
    println amountOfTables
}

The question is: Why can I get access to howManyTables task from config.gradle. But can't get access to defined variable? I want to create custom config.gradle with predefined values. And then use them as variables in my Android app. (like baseURL, type of data, etc...). And them, depending of that data build my logic. Anyway, the question is clear i hope ;) Any ideas?

like image 259
Rishka Avatar asked Feb 20 '15 12:02

Rishka


1 Answers

Because You defined the variable with def - so it's local in the script itself. Try:

config.gradle

project.ext.amountOfTables = 15

build.gradle

apply from: 'config.gradle' //correct path should be here
println project.amountOfTables
like image 161
Opal Avatar answered Oct 17 '22 15:10

Opal