0

I've been working on an application that is running on multiple different AR headsets that all run different versions of Android. I have several different build flavors for the different versions:

    rej {
        compileSdkVersion 'Recon Instruments:Recon Instruments SDK Add-On:16'
        applicationId "edu.cnu.nasa.hud.reconjet"
        versionName "1.0-rej"
        minSdkVersion 16
    }
    gls {
        compileSdkVersion 23
        applicationId "edu.cnu.nasa.hud.glass"
        versionName "1.0-gls"
        minSdkVersion 19
    }
    vuz_100 {
        compileSdkVersion 23
        applicationId "edu.cnu.nasa.hud.vuzix_100"
        versionName "1.0-vzx_100"
        minSdkVersion 15
    }

The issue I'm having is that the application crashes when GDK specific classes are used. The GestureDetector causes java.lang.ExceptionInInitializerError to be thrown when running on any device that's not Glass. I can't understand why, since I'm only initializing and using it when the build flavor name contains "gls".

private void addGesturesForGlass(){
    if(BUILD_FLAVOR.contains("gls")) {
        gestureDetector = new GestureDetector(this);
        gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
            @Override
            public boolean onGesture(Gesture gesture) {
                switch (gesture) {
                    case SWIPE_RIGHT:
                        //This is a forward swipe
                        advanceColorShift();
                        return true;
                    case SWIPE_LEFT:
                        //This is a back swipe
                        return true;
                }
                return false;
            }
        });
    } else {
        gestureDetector = null;
    }
}

According to Logcat, the exception that ultimately raises the error originates from the switch(gesture) line, but that line is never reached on any device besides glass. Is there a way to have this code present in all flavors without causing the error?

sjyn
  • 99
  • 2
  • 9
  • You should check the device at runtime, big at build time, `Build.DEVICE.contains("glass")` – Alex Cohn Jul 07 '16 at 16:05
  • I still get the error on both Vuzix and Recon Jet headsets. – sjyn Jul 07 '16 at 17:54
  • You can make your compare string more exclusive. Check https://github.com/jaredrummler/AndroidDeviceNames library. Also, this discussion may be helpful: http://optinvent.proboards.com/thread/11/which-android-build-properties-identify – Alex Cohn Jul 07 '16 at 18:21

0 Answers0