Jempis
Jempis

Reputation: 93

android studio gradle define a local variable

i want to create inside in my gradle.build file a local variable, because i have two different productFlavors with two differet path for jnlibs. Then i use this gloabl variable to set this different path, for example for use in within the section dependies.
I want to do this:

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {

    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    def pathLibs;

    productFlavors {

        project1 {
            applicationId "com.test.project1"
            minSdkVersion 15
            targetSdkVersion 21
            versionCode=76
            versionName="5.2.6"
            pathLibs 'src/project1/jniLibs'
        }

        project2 {
            applicationId "com.test.project2"
            minSdkVersion 15
            targetSdkVersion 21
            versionCode=66
            versionName="5.2.2"
            pathLibs 'src/project2/jniLibs'
        }
    }

}


dependencies {

    compile 'com.google.android.gms:play-services-cast:6.5+'
    compile 'com.android.support:appcompat-v7:22.1.0'



        compile files(pathLibs+ '/voOSBasePlayer.jar')
        compile files(pathLibs+ '/assets.jar')
        compile files(pathLibs+ '/DxDrmDlc.jar')
        compile files(pathLibs+ '/voOSBasePlayer.jar')
        compile files(pathLibs+ '/voOSDataSource.jar')
        compile files(pathLibs+ '/voOSEngine.jar')
        compile files(pathLibs+ '/voOSHDMICheck.jar')
        compile files(pathLibs+ '/voOSPlayer.jar')
        compile files(pathLibs+ '/voOSStreamingDownloader.jar')
        compile files(pathLibs+ '/voOSUtils.jar')


}

you can create the variable "pathLibs" as in the example described above? Thanks

Upvotes: 1

Views: 1774

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364978

To define a global variable you can use something like this:

project.ext.set("pathLibs", value)

To access it from anywhere in the project:

project.pathLibs

Using def pathLibs; it becomes a local variable.

You can find more info here.

Upvotes: 2

Related Questions