I want to create 2 versions of Fragment for different build variant, like whole code gonna be different in flavor 1 than in flavor 2. I wanna solve this without doing if-else based on BuildConfig.FLAVOR parameter in code. That means if I have MapFragment, I want to have exact same class named MapFragment with different code when different flavor is built. Reason why I want to do it is that I don't want to have any reference to this MapFragment from other version(flavor
in any logs or specifics on my App. This should work similarly like string.xml localization is working or dimens.xml. Is there any way how to achieve it?
Reason for this is that I'm using Huawei map and ag-connect services and also Google Play map. Problem is that Huawei is using some background location service which is then rejecting my app on Google Play. This Huawei flavor should never be available on Google Play, it is like standalone copy of App for Huawei Shop.
That means if I build .apk from Google Play (flavor 1), I will not include any ag-connect services or classes or references/imports from Huawei flavor and vice-versa.
UPDATE:
As I checked comment below, I tried to create sourceSets and reimplement my flavors to those new sets. But it still cant compile.
Also I need to know how to combine those flavors with types and sources. Because I have 2 main sources: google and huawei. Then I need 4 flavors for each of these sources like googleProd, googleProdTest, googleDev, googleDevTest and same for huawei and also all of those should have build type debug/release in case I want to release them to Google Play store for testing. Problem is that I need something like product subflavors. Each huawei flavor (prod, test, dev, dev-test) will use huawei sourceSet (main+huawei) and each google flavor (prod, test, dev, dev-test) will use google sourceSet(main+google). That means main sources will be code which is common for both and google/huawei sources has different version of same Fragment.
So these should be final buildVariants:
- googleProd (main+google src)
- googleTest (main+google src)
- googleDev (main+google src)
- googleDevTest (main+google src)
- huaweiProd (main+huawei src)
- huaweiTest (main+huawei src)
- huaweiDev (main+huawei src)
- huaweiDevTest (main+huawei src)
and release/debug build type for all 8. So total of 16 variants.
That means I need to know how to merge google src with prod, test, dev and dev-test flavors and huawei src with huaweiProd, huaweiTest, huaweiDev and huaweiDev-test flavors so I dont need to have 4 huawei Fragments which are identical and 4 google fragments which are identical for all flavors. It should work like abstract class/parent class.
A problem occurred evaluating project ':app'.
No signature of method: build_1t7zaa85nxlbgjo4n3n9fcb4s.android() is applicable for argument types: (build_1t7zaa85nxlbgjo4n3n9fcb4s$_run_closure1) values: [build_1t7zaa85nxlbgjo4n3n9fcb4s$_run_closure1@56b08118]
Code Gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//Google Crashlytics
apply plugin: 'com.google.firebase.crashlytics'
//Google Services
apply plugin: 'com.google.gms.google-services'
//Kotlin
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
def code = getVersionCodeTimestamp()
defaultConfig {
applicationId "----"
minSdkVersion 21
targetSdkVersion 29
versionCode code
versionName "2.5.5"
vectorDrawables.useSupportLibrary = true
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
signingConfigs {
app{
...
}
}
buildTypes {
release {
manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.app
}
debug {
manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
signingConfig signingConfigs.app
}
}
sourceSets {
google {
java.srcDirs('src/main/java', 'src/google/java')
}
huawei {
java.srcDirs('src/main/java', 'src/hua/java')
}
}
flavorDimensions "production"
productFlavors {
google {
prod {
dimension "production"
...
}
test {
dimension "production"
...
}
dev {
...
}
dev_test {
...
}
}
huawei {
prod {
dimension "production"
...
}
test {
dimension "production"
...
}
dev {
...
}
dev_test {
...
}
}
}
}
dependencies {
implementation project(':pin')
//Kotlin SDK
implementation 'androidx.core:core-ktx:1.3.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
//Kotlin Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
//AndroidX
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'androidx.palette:palette-ktx:1.0.0'
//Google SDK
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.maps.android:android-maps-utils:2.0.3'
implementation 'com.google.zxing:core:3.4.0'
//Google Crashlytics SDK
implementation ('com.google.firebase:firebase-crashlytics:17.2.2') {
transitive = true
}
//Google Analytics SDK
implementation 'com.google.firebase:firebase-analytics:18.0.0'
//Google Firebase Messaging
implementation 'com.google.firebase:firebase-messaging:21.0.0'
implementation 'com.google.firebase:firebase-core:18.0.0'
//Huawei SDK
huaweiImplementation 'com.huawei.hms:identity:4.0.1.300'
huaweiImplementation 'com.huawei.hms:location:4.0.3.303'
huaweiImplementation 'com.huawei.hms:maps:4.0.1.301'
}