Google Glass GDK backward compatibility?

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

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

      

(the old map constructor is deprecated, the Builder template replaces 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 the SDK_INT won't update when a new sdk is released.

What's the correct way to handle this? Is there a better way than using reflection to check for the existence of certain classes?

Did I miss something?

Edit:

Based on the API demo, it looks like we don't care. Let it break on old XEs. Hopefully all glasses will be updated soon. See https://github.com/googleglass/gdk-apidemo-sample/commit/e644c7325bb74a02b0f383bf9f19e9f851313dc2

+3


source to share


3 answers


For now I would use reflection ... Possibly:

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 old XEs because I missed XE 21.

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

+2


source


Are you on XE21.0 or XE20.1? If you are on XE20.1 then CardBuilder is not available. You will need to wait for your device to update this week when XE21.0 starts rolling out this week.

In terms of checking the Glass version, the specific setting is currently low. In general, although even if the GDK classes are deprecated, they will be mostly available in future releases so as not to break backward compatibility. So you are probably better off sticking with the old API, even if it's deprecated, for a few more releases.



With that said, besides using reflection, you can 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, although it hasn't been announced on which incremental version for each version (you'll have to experiment to find this).

+1


source


Since Google Glass is still in "beta" we will need to update to the current version of the GDK whenever a new version is released. New releases were made almost monthly.

I expect that after Google Glass releases a public form on it, there might be a "minimum sdk version" supported ... but this announcement has not yet been made by Google.

So, stay tuned for changes as every version of the GDK is released (and fixes issues or adds features), so you (and the rest of us) can keep our nascent glassware (or "swamp") running).

-1


source







All Articles