我有一个使用Google的Inapp结算服务和IABHelper课程的项目。一切正常,直到我将Android Studio更新为最新的"稳定"发布和Gradle从0.8.x到1.0.x。
我跟着Migrating Gradle to 1.0.0 steps。但不幸的是,我得到了dexDebug的以下错误: 错误代码1;意外的顶级例外:com.android.dex.util.ExceptionWithContext。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dexDebug'.
> 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.<init>(ConcreteMethod.java:87)
at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:75)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
... 22 more
...while processing <init> (Lcom/mytowntonight/aviationweather/MainActivity;)V
...while processing com/mytowntonight/aviationweather/MainActivity$1.class
1 error; aborting
我尝试更新构建工具 - 没有成功。
我终于找到了一种方法来重新编译它,通过注释掉以下代码片段:
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
}
}
);
}
};
但是这段代码基本上是来自Google的Inapp结算教程的副本,它在Gradle / Android Studio更新之前编译得很好。 仅供参考:IabHelper.OnIabSetupFinishedListener是一个公共接口。
任何想法,问题是什么? 谢谢!
答案 0 :(得分:1)
通过将Googles In App Billing帮助程序类更新为最新版本,最终解决了该问题。它们是计费演示/示例的一部分,在我第一次实施计费后已经更改。
答案 1 :(得分:0)
我很多次遇到过这个问题。我不知道这个问题的根本情况是什么,但Linux上最简单的解决方案是重新启动计算机或注销然后再次登录。如果重启/重新登录有帮助,看起来这个问题与某种缓存有关。
您也可以尝试清理构建,有时可能会有所帮助,但并非总是如此。使用终端:
gradlew clean