Created
February 15, 2019 11:21
-
-
Save neyguvj/391a20b40e04348d5dbe8201ac015282 to your computer and use it in GitHub Desktop.
Set default build variant witn variant filter (workaround)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 28 | |
defaultConfig { | |
applicationId "com.example.variantfilter" | |
minSdkVersion 21 | |
targetSdkVersion 28 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
flavorDimensions "api", "mode" | |
productFlavors { | |
demo { | |
// Assigns this product flavor to the "mode" flavor dimension. | |
dimension "mode" | |
} | |
full { | |
dimension "mode" | |
} | |
minApi24 { | |
dimension "api" | |
minSdkVersion 24 | |
versionCode 30000 + android.defaultConfig.versionCode | |
versionNameSuffix "-minApi24" | |
} | |
minApi23 { | |
dimension "api" | |
minSdkVersion 23 | |
versionCode 20000 + android.defaultConfig.versionCode | |
versionNameSuffix "-minApi23" | |
} | |
minApi21 { | |
dimension "api" | |
minSdkVersion 21 | |
versionCode 10000 + android.defaultConfig.versionCode | |
versionNameSuffix "-minApi21" | |
} | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
} | |
} | |
// You can add property to force one build variant for your project. | |
// Then you can set it in your gradle.properties file like this: | |
// `forceBuildVariant=minApi24DemoDebug`and implement variant filter in your project. | |
// | |
// If you have different flavors and dimension in other modules you need to implement own | |
// variant filters in each module. | |
// If you already have variant filter, you need to modify it because you can't set multiple | |
// variantFilter in one module. | |
// Here you can read this property | |
def forceBuildVariant = project.properties.forceBuildVariant | |
if (forceBuildVariant) { | |
variantFilter { | |
// Here you can ignore all other build variants of your project. | |
// Filtering of other variants also speeds up project configuration and synchronization | |
// in Android Studio. But after this you will unable to choose any other build | |
// variants in Android Studio. | |
it.ignore = it.name != forceBuildVariant | |
} | |
} | |
} | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation 'com.android.support:appcompat-v7:28.0.0' | |
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment