Reputation: 221
i am adding in build.gradle(Module:app) the following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.sis.newpro"
minSdkVersion 22
targetSdkVersion 25
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
productFlavors {
prod {
buildConfigField 'String', 'URL', '"http://api.abcd.com"'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
giving Error:(22, 0) Could not find method productFlavors() for arguments [build_bqh9qnip9k7nqy2kbpova0vtq$_run_closure2@5b30b3a7] on project ':app' of type org.gradle.api.Project.
do i missing any thing to add in build.gradle(Module:app) or do i need to add any thing to build.gradle(Project:NewProject)
Upvotes: 1
Views: 2569
Reputation: 12866
Move your productFlavors
tag inside the android
braces, it needs to be a sibling of buildTypes
.
Your build.gradle would end up being something like this:
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.sis.newpro"
minSdkVersion 22
targetSdkVersion 25
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
prod {
buildConfigField 'String', 'URL', '"http://api.abcd.com"'
}
}
}
Upvotes: 4
Reputation: 173
Follow below steps to create build flavour :
productFlavors {
TestFlavourType {
applicationId "com.test.flavour"
minSdkVersion 17
targetSdkVersion 25
versionCode 3
versionName "1.02"
multiDexEnabled true
}
Defining Source Sets to pick from different folders:
sourceSets {
main { //Main
manifest.srcFile 'src/main/AndroidManifest.xml' - picks from Main
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
If you want to maintain different layout/styles/String u need to define as follows :
TestFlavourType {
res.srcDirs = ['src/TestFlavourType/res-TestFlavourType', 'src/CommonLayoutDir/res']
// For resources it will look for the files in this path [src/TestFlavourType/res-TestFlavourType] else it will look in to this [src/CommonLayoutDir/res]
assets.srcDirs = ['src/TestFlavourType/assets', 'src/main/assets']
}
}
}//productFlavors end
Under Src directory create a folder to Maintain separate layout files for different flavors.Please let me know if it helps.
Upvotes: 1