am 10fd7f6b: am ca2c6307: am 87be67f9: Fix layoutlib [DO NOT MERGE]

* commit '10fd7f6b4192fdbd847106fb0d9ec87095092ee3':
  Fix layoutlib [DO NOT MERGE]
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
index 0963c2e..5cb49d3 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
@@ -248,11 +248,16 @@
      * The counterpart is {@link #setUp()}.
      */
     private void tearDown() {
-        // Make sure to remove static references, otherwise we could not unload the lib
-        mContext.disposeResources();
+        // The context may be null, if there was an error during init().
+        if (mContext != null) {
+            // Make sure to remove static references, otherwise we could not unload the lib
+            mContext.disposeResources();
+        }
 
-        // quit HandlerThread created during this session.
-        HandlerThread_Delegate.cleanUp(sCurrentContext);
+        if (sCurrentContext != null) {
+            // quit HandlerThread created during this session.
+            HandlerThread_Delegate.cleanUp(sCurrentContext);
+        }
 
         // clear the stored ViewConfiguration since the map is per density and not per context.
         ViewConfiguration_Accessor.clearConfigurations();
@@ -263,8 +268,12 @@
         sCurrentContext = null;
 
         Bridge.setLog(null);
-        mContext.getRenderResources().setFrameworkResourceIdProvider(null);
-        mContext.getRenderResources().setLogger(null);
+        if (mContext != null) {
+            mContext.getRenderResources().setFrameworkResourceIdProvider(null);
+            mContext.getRenderResources().setLogger(null);
+        }
+
+        mContext = null;
     }
 
     public static BridgeContext getCurrentContext() {