Do a sanity check on SDK template versions.

Do a quick check to ensure the template directory exists and is of
a compatible-ish version. Bad templates cause obscure problems with
the NPW and/or its generated projects.

Bug: 8853481
Change-Id: I94c85f5a22de29c02aa6e5383a509e800309882f
diff --git a/android/src/com/android/tools/idea/wizard/ b/android/src/com/android/tools/idea/wizard/
index aa160f6..82c7887 100644
--- a/android/src/com/android/tools/idea/wizard/
+++ b/android/src/com/android/tools/idea/wizard/
@@ -24,6 +24,7 @@
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.ProjectJdkTable;
 import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.ui.Messages;
@@ -57,6 +58,13 @@
   protected void init() {
+    // Do a sanity check to see if we have templates that look compatible, otherwise we get really strange problems. The existence
+    // of a gradle wrapper in the templates directory is a good sign.
+    if (!(new File(TemplateManager.getTemplateRootFolder(), "gradle/wrapper/gradlew").exists())) {
+      String msg = "Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.";
+      Messages.showErrorDialog(myContentPanel, msg);
+      throw new IllegalStateException(msg);
+    }
     myWizardState = new NewProjectWizardState();
     myConfigureAndroidModuleStep = new ConfigureAndroidModuleStep(this, myWizardState);