How can the import section of an Android Java program be conditionally compiled? I know we can conditionally compile classes in Java code using @TargetApi(). However, @TargetApi() does not work for the import section at the top of the java file.
In particular, I want to be able to ignore these import statement when compiling with compileSdkVersion and targetSdkVersion of 27. However, I want to keep these statements in the code and compile them when compileSdkVersion and targetSdkVersion are 30, or above. I wish the following code worked, but does not. Any suggestions?:
@TargetApi(30) // <== This statement does not work in this section, alternatives?
import android.net.wifi.WifiNetworkSuggestion
import static android.provider.Settings.ACTION_WIFI_ADD_NETWORKS;
import static android.provider.Settings.EXTRA_WIFI_NETWORK_LIST;
question from:
https://stackoverflow.com/questions/65846423/conditionally-compile-android-java-import-statements 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…