I am developing an Android application with Android Studio which will use industrial devices with barcode scanners. Some of them (different models from different companies) use a special SDK (I have to compile with a special SDK, not just API 23 for example).
My problem is that when I switch to an other device and I have to compile with an other SDK (or just API 23 for example), I have some code that doesn't work anymore : the imports don't exist so the objects and methods I use for a specific device neither.
My code looks like this :
if(Build.MANUFACTURER.equals(COMPANY_NAME)){
// do some stuff that won't compile with an other sdk
}else if (Build.MANUFACTURER.equals(COMPANY_NAME)){
// do some other stuff that compile with a specific sdk too...
}else if (...){
...
}
I don't want to remove the code or put it in commentaries since it will be executed only on specific devices (and I don't want to come back uncomment some code each time I want to compile for a specific SDK).
How can I do to keep my code (and not necessarly put it in commentaries) without showing errors for others SDK?
What I have found so far :
- compileSdkVersion seems to not be able to be set in product flavors
we can put the compileSdkVersion depending on a condition like this :
if (condition) {
compileSdkVersion 23
} else {
compileSdkVersion 'Datalogic:Datalogic SDK v1:23'
}
But the condition can't be from product flavors since it's executed after that. A "solution" is to put the condition in gradle.properties as mentionned here but it has to be changed every time I compile manually and doesn't solve my problem hanving some code that don't compile on a specific SDK version.