3

I just tried out the updated gdk on my glass XE 20.1 and my testing app crashed because the new api is not available.

CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);

(The old Card constructor is deprecated. Builder pattern is replacing it.)

Log:

09-09 00:27:16.239    1992-1992/com.prat.testgdk E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.prat.testgdk, PID: 1992
java.lang.NoClassDefFoundError: com.google.android.glass.widget.CardBuilder
        at com.prat.testgdk.MainActivity.buildView(MainActivity.java:95)
        at com.prat.testgdk.MainActivity.onCreate(MainActivity.java:40)

On other Android devices, I can check android.os.Build.VERSION.SDK_INT or set minSdkVersion but on Glass SDK_INT won't get updated when the new sdk comes out.

What's the proper way to deal with this? Is there a better way than using reflection to test for the availability of specific classes?

Am I missing something?

Edit:

Based the API demo, it seems like we shouldn't care. Let it break on the old XEs. Hopefully, all Glasses are getting updated soon. See https://github.com/googleglass/gdk-apidemo-sample/commit/e644c7325bb74a02b0f383bf9f19e9f851313dc2

pt2121
  • 11,720
  • 8
  • 52
  • 69

3 Answers3

2

For now, I'd use reflection...Probably:

private View buildView() {
    try {
        String cardBuilderName = "com.google.android.glass.widget.CardBuilder";
        Class clazz = Class.forName(cardBuilderName);
        CardBuilder cardBuilder = new CardBuilder(this, CardBuilder.Layout.TEXT);
        cardBuilder.setText(R.string.hello_world);
        return cardBuilder.getView();
    } catch (Exception e) {
        //ClassNotFoundException?
        Log.v(TAG, e.toString());
        Card card = new Card(this);
        card.setText(R.string.hello_world);
        return card.getView();
    }        
}

Note: I haven't tested on old XEs because I've flashed the XE 21.

But this is ugly. Hopefully, we have a better way to handle this.

pt2121
  • 11,720
  • 8
  • 52
  • 69
1

Are you on XE21.0 or XE20.1? If you are on XE20.1, then CardBuilder is not available. You'll need to wait until your device is updated sometime this week as XE21.0 started rolling out this week.

In terms of checking the runtime version of Glass, definitely the setup currently is not great. Generally though even if GDK classes are deprecated, they will largely be available in future releases to not break backwards compatibility. So you are probably better off sticking with the old API, even if it is deprecated, for several more releases.

With that said, besides using reflection, you could check the incremental build version (http://developer.android.com/reference/android/os/Build.VERSION.html#INCREMENTAL). This should have a 1:1 mapping with the XE releases, though its not advertised as to what the incremental version is for each release (you'll have to experiment to find this).

Brandon Wuest
  • 206
  • 1
  • 2
-1

Since Google Glass is still in a "beta" state, we will need to upgrade to the current GDK version whenever a new release is made. New releases have been made almost monthly.

I expect that once Google Glass has been released in it public form, that the "minimum sdk version" may be supported ... but that announcement has not been made by Google yet.

So .. keep a close eye on changes as each version of the GDK is released (and patches correct problems or add features) so you (and the rest of us) can keep our nascent Glassware (or "to bo" Glassware will continue to run).

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37