Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android build.gradle importing flavors from another file

I have put the product Flavors into another file called other.gradle and it looks like this:

project.ext.myflavors =  {
 mock {
     applicationId "com.mysite.mock"
 }

}

and i am able to successfully access the closure in my build.gradle file like this:

myflavors()

but i get an error that mock method is not defined.

Error:Gradle DSL method not found: 'mock()'

Is there no way to just define code from another file and import the code itself into the build file ? Or how can i import the flavors from another file ?

like image 341
j2emanue Avatar asked Dec 24 '22 16:12

j2emanue


1 Answers

The build flavors could be defined in a separate file (build_flavors.gradle) like this:

android {
    productFlavors {
        flavorA {
            // ...
        }
        flavorB {
            // ...
        }
    }
}

and then imported into build.gradle:

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

android {
    // the rest of your android configuration
}
like image 178
sfera Avatar answered Dec 31 '22 12:12

sfera