title: Google Inapp Billing causes UNEXPECTED TOP-LEVEL EXCEPTION after updating Android Studio and Gradle
body: <p>I have a project which uses Google's Inapp Billing Service and the IABHelper classes. And everything worked just fine until I updated Android Studio to it's latest "stable" release and Gradle from 0.8.x to 1.0.x .</p>
  
  <p>I followed the <a href="http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0" rel="nofollow">Migrating Gradle to 1.0.0 steps</a>. But unfortunately I get the following error for dexDebug:
  Error Code 1; UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.util.ExceptionWithContext.</p>
  
  <pre><code>    FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':app:dexDebug'.
  &gt; com.android.ide.common.internal.LoggedErrorException: Failed to run command:
      C:\Program Files (x86)\Android\sdk\build-tools\android-4.4W\dx.bat --dex --no-optimize --output C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\dex\debug C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\classes\debug C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\support-annotations-21.0.3-d2173d36e782fa1d3f28e5e6281942ff95c70054.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\classes-6fc46c00ee854d5ca04c7a8678700fa00a807727.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\classes-583108ab433986d269f15fc874476a6a41305753.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\internal_impl-21.0.3-ddf1e2aa24f08302c35d4c53fd9a54e9d3e92c3b.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\StartAppInApp-2.4.11-6ad73d6077f6fe9aae60a40cb9dad0f7ce3f2b17.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\classes-27d7f4d4f4a892505176f27373375f50da12ca15.jar C:\Programmierung\Android_Studio\Aviation\AviationWeather\app\build\intermediates\pre-dexed\debug\libGoogleAnalyticsServices-0f3d24de5fad89dd5a88c6c233a890b5f2a4b117.jar
  Error Code:
      1
  Output:
  
      UNEXPECTED TOP-LEVEL EXCEPTION:
      com.android.dex.util.ExceptionWithContext
          at com.android.dex.util.ExceptionWithContext.withContext(ExceptionWithContext.java:45)
          at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:371)
          at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:139)
          at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:94)
          at com.android.dx.command.dexer.Main.processClass(Main.java:682)
          at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
          at com.android.dx.command.dexer.Main.access$600(Main.java:78)
          at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
          at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
          at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
          at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
          at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
          at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
          at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
          at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
          at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
          at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
          at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
          at com.android.dx.command.dexer.Main.processOne(Main.java:596)
          at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
          at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
          at com.android.dx.command.dexer.Main.run(Main.java:230)
          at com.android.dx.command.dexer.Main.main(Main.java:199)
          at com.android.dx.command.Main.main(Main.java:103)
      Caused by: java.lang.NullPointerException
          at com.android.dx.cf.code.ConcreteMethod.&lt;init&gt;(ConcreteMethod.java:87)
          at com.android.dx.cf.code.ConcreteMethod.&lt;init&gt;(ConcreteMethod.java:75)
          at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
          ... 22 more
      ...while processing &lt;init&gt; (Lcom/mytowntonight/aviationweather/MainActivity;)V
      ...while processing com/mytowntonight/aviationweather/MainActivity$1.class
  
      1 error; aborting
  </code></pre>
  
  <p>I tried updating the build tools - no success.</p>
  
  <p>I finally found a way to compile it again, by commenting out the following code snippet:</p>
  
  <pre><code>IabHelper.OnIabSetupFinishedListener IABListener = new IabHelper.OnIabSetupFinishedListener() {
                  public void onIabSetupFinished(IabResult result) {
                      if (!result.isSuccess()) {
                          // There was a problem, setting up billing
                          Log.d("Avia: Billing", "Problem setting up In-app Billing: " + result);
                      }
  
                      // Hooray, IAB is fully set up!
                      mHelper.queryInventoryAsync(true,
                          new IabHelper.QueryInventoryFinishedListener() {
                              @Override
                              public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                                  if (result.isFailure())
                                      return;
  
                                  // handle Purchase
                              }
                          }
                      );
                  }
              };
  </code></pre>
  
  <p>But this code is basically a copy from Google's Inapp Billing Tutorials and it compiled just fine until the Gradle / Android Studio update.
  FYI: IabHelper.OnIabSetupFinishedListener is a public interface.</p>
  
  <p>Any ideas, what the problem is?
  Thank you!</p>