I have an Android application with several flavors, each one for a different environment. I wish to specify on which of these flavors the HockeyApp SDK is imported and initialized (or at least to be able to use it in all flavors except one).
Currently I have this line on the build.gradle
file:
dependencies {
...
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
...
}
and on the main Application.java
file, the HockeyApp SDK is imported and initialized:
import net.hockeyapp.android.CrashManager;
@Override
public void onCreate(){
super.onCreate();
CrashManager.register(this);
...
}
The current workaround is to comment these lines each time i need to build and/or generate an .apk file for the flavor which I don't want to include the HockeyApp SDK. Surely there's a better way to handle this.
I've tried to create different Application.java files and place them inside app/src/{flavor}
(following the same logic of different resources for different flavors), but I could not build the application because every reference for the Application
class was "flavor independent" eg. each class that imported the Appplication
class simply had the line:
import {package}.Application;
Thinking the other way around, if I specify on the build.gradle
specific implementation for each flavors eg.
{flavor1}Implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
{flavor2}Implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
then I'm unable to build the other flavors because the package reference doesn't exist for them.
I hope I was able to explain my question. If you need further explanations or details about the current application's implementation, I'm happy to provide them.
Thanks in advance.