I am using a simple conditional check on Build.Version.SDK_INT in the onCreate method of my application (code below) to prevent strict mode being enabled on any Android OS earlier than 2.3. Up until recently this had been working fine, but after a re-jig of my project, I receive the following error:
Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method com.myPackage.MyApp.onCreate
I have heard that the way class dependencies were evaluated and loaded changed from a static analysis of the class to a 'lazy loading' system in Android 2.0, but since I am using 2.2, I don't think this is at play. I suspect there is something elsewhere in my project structure that is causing this error, but I am at a loss as to what that might be.
Has anyone here had a similar experience and could maybe shed some light on this? Any help would be gratefully received.
Thanks in advance for your help!
Please see my code below for reference:
public class MyApp extends Application {
@Override
public void onCreate() {
// Set up strict mode
int buildInt = Build.VERSION.SDK_INT;
Log.d(LogTags.TRIGGER_CODE, String.format("Build is %d (%s)", buildInt, Build.VERSION.CODENAME));
if (buildInt >= 9) {
StrictMode.setThreadPolicy(new ThreadPolicy.Builder()
.detectCustomSlowCalls()
.detectNetwork()
.build());
StrictMode.setVmPolicy((new VmPolicy.Builder()
.detectAll()
.build()));
}
super.onCreate();
}
}