I have two productFlavors
productFlavors { dev { ... } ble { ... } }
Now, I created a different source set for ble
where I added few extra Java classes.
So I have two sets of directories now:
app/src/main/java/...
app/src/ble/java/...
In the ble
set, I have a Java class called BLEUtil.java
app/src/ble/java/.../BLEUtil.java
I want to call a method that is in BLEUtil.java
from my MainActivity
BLEUtil.startScan();
When the build variant is set to bleDebug
, it works great because BLEUtil.java
exist.
However, when I change my build variant to devDebug
, BLEUtil.java
does not exist so BLEUtil.startScan()
throws an error and I can’t build the app.
error: cannot find symbol class BLEUtil
Do I have to comment and uncomment those lines out manually or is there any other way?
Advertisement
Answer
Assuming that MainActivity
is in main
, you can:
Have a
BLEUtil
class indev
as well, with the same API, perhaps implemented as a no-op; orHave two
MainActivity
implementations, one indev
and one inble
, where only the one inble
usesBLEUtil
, and perhaps with some common base class inmain
that has the common functionality; orHave
MainActivity
inherit from aFlavoredActivity
, where you have implementations ofFlavoredActivity
in bothdev
andble
, where the latter usesBLEUtil
There may be other approaches as well.