in my Android project I configured a dimension with 3 variants (example: mock, dev, prod). I also have the default build types (debug, release) where I have their implementation of Application:
src/debug/java/package/MyApplication.kt
src/release/java/package/MyApplication.kt
So I can generate 6 builds (mockDebug, mockRelease, devDebug, devRelease, etc.)
Now my mockDebug variant needs a specific implementation of MyApplication.kt.
As I read here
I can do this creating a class MyApplication in this path: src/mockDebug/java/package/MyApplication.kt
However I'm receiving an error in Android Studio saying "Redeclaration: MyApplication".
I'm sure I can solve this problem moving all debug/release MyApplication.kt implementations into
directories, but I don't understand why the documentation says it can be possible, even if I'm receiving that error
Thanks for helping me
In my case deleting /build
folder solved the issue.
"Redeclaration: MyApplication" You see this above error as its present in the main and in your flavour or variant
approach should be class or file you want to change should not be in main makes copies of that file and add them to flavour or variant and do the change you want to see.
You can try implementing your Gradle in this manner. In Build.gradle:
buildTypes {
release {
debuggable false
minifyEnabled true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
zipAlignEnabled false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
mock {
minSdkVersion 17
applicationId 'com.test.mock'
targetSdkVersion 23
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 1
versionName '1.0'
}
dev {
minSdkVersion 17
applicationId 'com.test.dev'
targetSdkVersion 23
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 1
versionName '1.0'
}
prod {
minSdkVersion 17
applicationId 'com.test.prod'
targetSdkVersion 23
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 1
versionName '1.0'
}
}
So, now you can have the folder structure like:
/src/mock/Application.kt
/src/dev/Application.kt
/src/prod/Application.kt
So once you build the Project, select the variant from BuildVariant tabs so it will take respective Application.kt.
Hope this will help to solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With