I would create a stub EasyTracker class that implements the same API but does nothing (or perhaps logs output only in a debug build). That will require the fewest changes in the rest of your code.
You could include this stub class in flavors that don't import the Analytics library.
Your stub EasyTracker class would look something like this. I haven't actually compiled this code, so you'll need to figure out imports and fine-tune it (You'll have to work around the other analytics classes that it needs for imports; either mock them as well or try to include them from the Analytics library without picking up the real version of EasyTracker, though that could be tricky -- maybe help yourself out by only including stub versions of the method calls you actually use), but this should get you started:
package com.google.android.apps.analytics.easytracking;
public class EasyTracker {
private static final EasyTracker INSTANCE = new EasyTracker();
public static EasyTracker getTracker() {
return INSTANCE;
}
void addItem(Item item) {}
void addTransaction(Transaction transaction) {}
void clearTransactions() {}
void dispatch() {}
// Stub out all the rest of the methods like this
}
Basically you implement all the methods in the EasyTracker
class API, but they're all empty method bodies. Note that this class is in the same package as the real version that actually does something. This means that you can swap this stub class in for the original with no changes to the code that calls it.
You could either compile this class to a jar file and include the jar in the flavors that need it, or you could make it a plain Java module.
Then you need to selectively include the code in the flavors that need it. You probably already have dependencies that look something like this:
dependencies {
....
compile files('libs/libGoogleAnalyticsV2.jar')
}
Make the dependency on the Analytics library dependent on the flavor:
dependencies {
compile 'com.android.support:appcompat-v7:+'
flavor1Compile files('libs/libGoogleAnalyticsV2.jar')
flavor2Compile project(':MockAnalytics')
}