0

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();
     }
 }
head in the codes
  • 1,159
  • 12
  • 24
  • 1
    This should help you: [StrictMode for lower platform versions](http://stackoverflow.com/a/4623606/2558882) – Vikram Jul 22 '13 at 22:12
  • Thanks, that seems like a good fix but since I'm not supporting pre 2.0, I'd rather work out what change has caused this error to appear and fix that problem. I don't really want to add complexity for something that was previously working and probably has a simple fix.. – head in the codes Jul 22 '13 at 22:46
  • Quick clarification: Is this a compile-time error, or an error on the device when you try to run the application? I initially thought on-device error, but that error message looks more like a compiler error. – JesusFreke Jul 23 '13 at 01:08
  • `SDK_INT` is public static final, which means its value is evaluated at compile time rather than runtime. I'm guessing this got altered when you rearranged the project, though you should see that in the log message. – fadden Jul 23 '13 at 17:22

1 Answers1

0

This turned out to be just a symptom of another problem elsewhere in code, far too specific to the project to be worth going into here...

Thanks for the thoughts on the root cause here, and sorry for the 'doh' moment :)

head in the codes
  • 1,159
  • 12
  • 24