试图建立与蚂蚁的Andr​​oid应用程序时ExceptionWithContext被抛出抛出、应用程序、蚂蚁、oid

2023-09-04 23:34:04 作者:触不可及i

我已经试过各地无论在谷歌和计算器的答案,这个搜索,但我一直无法找到任何人与我有确切的问题。我试图建立一个持续集成服务器(竹,特别是)进行更新,打造,每一次有人让源代码控制的变化导出APK。我在我的本地机器上运行到同样的错误既当我做的每一步手,在服务器上时,我用我已经成立了工作。当我到达构建的DEX步骤的错误发生。我已经得到了相同的输出,到目前为止与蚂蚁调试蚂蚁发布蚂蚁干净调试蚂蚁干净发布。整个DEX步骤的输出,完全错误,如下所示:

I've tried searching around both on Google and on stackoverflow for an answer to this, but I've been unable to find anyone with the exact issue I'm having. I'm attempting to set up a continuous integration server (Bamboo, specifically) to update, build, and export an APK every time someone makes a change in source control. I'm running into the same error both on my local machine when I do every step by hand and on the server when I use the job I've set up. The error happens when I reach the dex step of the build. I've gotten the same output so far with ant debug, ant release, ant clean debug, and ant clean release. The output of the entire dex step, complete with error, is as follows:

-dex:
      [dex] input: C:\Users\...\Android\bin\classes
      [dex] input: C:\Users\...\google-play-services_lib\bin\classes.jar
      [dex] input: C:\Program Files (x86)\Android\android-sdk\tools\support\annotations.jar
      [dex] input: C:\Users\...\Android\libs\FlurryAgent.jar
      [dex] input: C:\Users\...\Android\libs\gcm.jar
      [dex] input: C:\Users\...\Android\libs\android-support-v4.jar
      [dex] input: C:\Users\...\google-play-services_lib\libs\google-play-services.jar
      [dex] Pre-Dexing C:\Users\...\google-play-services_lib\bin\classes.jar -> classes-64c0adfe92ddc950c7ab8c5002ceabf2.jar
      [dex] Pre-Dexing C:\Program Files (x86)\Android\android-sdk\tools\support\annotations.jar -> annotations-62bab95d6948a2db17bbc7976160b014.jar
      [dex] Pre-Dexing C:\Users\...\Android\libs\FlurryAgent.jar -> FlurryAgent-499d43756a3ce626a64773e6dfd5eaec.jar
      [dex] Pre-Dexing C:\Users\...\Android\libs\gcm.jar -> gcm-ae2640f44640eb4fd7b13964b65d2d70.jar
      [dex] Pre-Dexing C:\Users\...\Android\libs\android-support-v4.jar -> android-support-v4-fa30b373a3e3ba9f2cf94900a9eb42fe.jar
      [dex] Pre-Dexing C:\Users\...\google-play-services_lib\libs\google-play-services.jar -> google-play-services-9efad6e9178399c185fae6c0b6bdc4c6.jar
      [dex] Converting compiled files and external libraries into C:\Users\...\Android\bin\classes.dex...
       [dx]
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] com.android.dx.util.ExceptionWithContext
       [dx]     at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
       [dx]     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:344)
       [dx]     at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
       [dx]     at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
       [dx]     at com.android.dx.command.dexer.Main.processClass(Main.java:487)
       [dx]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
       [dx]     at com.android.dx.command.dexer.Main.access$400(Main.java:67)
       [dx]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:135)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:422)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:209)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx]     at com.android.dx.command.Main.main(Main.java:91)
       [dx] Caused by: java.lang.NullPointerException
       [dx]     at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:87)
       [dx]     at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:75)
       [dx]     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:247)
       [dx]     ... 23 more
       [dx] ...while processing <init> (Lcom/.../android/LocationService;)V
       [dx] ...while processing com/.../android/LocationService$1.class
       [dx]
       [dx] 1 error; aborting

有关背景下,我使用Ant v1.9.2和Android集结工具v18.0.1在Windows机器上,我还没有编辑以任何方式构建脚本。我在他们两个目录生成一个用于应用程序,一个是使用 Android的更新项目--path库。。我还没有尝试过将其设置为自动使用正确的密钥库签署的是,虽然我的(有限)的理解是没有必要的,至少不是一个调试建立与蚂蚁。

For context, I'm using Ant v1.9.2 and Android build-tools v18.0.1 on a Windows machine and I haven't edited the build scripts in any way. I generated one for the app and one for the library using android update project --path . in their two directories. I also haven't tried setting it up to automatically use the proper keystore for signing yet, although to my (limited) understanding that shouldn't be necessary, at least not for a debug build with Ant.

有没有人看到过这个特殊的问题?它是与生成的.class文件有问题?构建文件?这是我第一次真正涉足建设有蚂蚁(我一般只让Eclipse中为我做所有的辛勤工作),所以我很少去。任何帮助将是非常美联社preciated。

Has anyone seen this particular issue before? Is it a problem with the generated .class file? The build files? This is my first real foray into building with Ant (I generally just let Eclipse do all the hard work for me), so I have very little to go on. Any help would be much appreciated.

更新:如果有人在关注这个问题,我的问题似乎已经解决了自身。如何以及为什么,我不知道。我想今天早上更新源(我们曾在一些变化),重新运行 Android的更新项目-p。,尝试了一个蚂蚁干净调试,你瞧,它的工作。象蚂蚁发布,甚至使用密钥签名得当我给它。我最好的猜测是,在那LocationService类文件很奇怪,但它是什么是超越我。

Update: In case anyone was paying attention to this question, my issue seems to have resolved itself. How and why, I don't know. I tried updating the source this morning (we had a few changes in), reran android update project -p ., tried an ant clean debug, and lo and behold, it worked. As did ant release, which even signed it properly with the key I gave it. My best guess is that there was something weird in that LocationService class file, although what it was is beyond me.

更新2:什么我说,我的第一个更新现在是无效的。我已经分离出的问题,但我没有接近理解它。的code此块是罪魁祸首:

Update 2: Anything I said in my first update is now invalid. I've isolated the issue, but am no closer to understanding it. This block of code is the culprit:

if (Settings.DEBUG) {
    Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            storeDebugNotification(AndroidUncaughtExceptionHandler.getStackTraceString(ex));
        }
    });
}

这就是事情变得怪异。当 Settings.DEBUG 标志,这将构建细跟蚂蚁。当它的,它失败了,给我上面显示的错误。当我评论了整个事情了,它正常工作与任 DEBUG 设置。这同样适用于具有如果(Settings.DEBUG)线及其注释大括号,但原封不动身体,以及评论身体,独自离开,如果部分。所以...我不知所措就在这里。一些有关的if语句和身体之间的互动,在这个特殊的文件,在 DEBUG 为假导致的问题。而另一个奇怪的是,我们有一个的完全一样的,如果在应用程序中的另一个文件块的(一个活动,而这一次是一个服务)。

Here's where things get weird. When the Settings.DEBUG flag is true, this builds fine with ant. When it's false, it fails, giving me the error shown above. When I comment the whole thing out, it works fine with either DEBUG setting. The same goes for having the if (Settings.DEBUG) line and its curly braces commented but the body left intact, as well as commenting the body and leaving the if portion alone. So... I'm at a loss here. Something about the interaction between the if statement and the body, in this particular file, when DEBUG is false is causing problems. And the other weird part is that we have that exact same if block in another file in the app (an activity, whereas this one is a service).

推荐答案

我有同样的异常在编制发布的项目。我的code是:

I had the same exception while compiling a project for release. My code was:

if (BuildConfig.DEBUG) {
    myView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Do something
        }
    });
}

由于 BuildConfig.DEBUG 是一个常数的值的错误,在code在该块被公认为是死code 和优化时删除。

Because BuildConfig.DEBUG is a constant with value false, the code in the block is recognized as dead code and removed when optimized.

在CfTranslator(类文件翻译)要创建一个单独的文件中的匿名类块(的 SomeClass的$ 1.class )内,但因为它是优化掉了会发生错误。我把匿名类的大括号的问题得到解决外:

The CfTranslator (Classfile Translator) wants to create a separate file for the anonymous class inside the block (SomeClass$1.class), but since it is optimized away an error will occur. I took the anonymous class outside the curly braces the problem was solved:

View.OnClickListener lClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Do something
    }
};

if (BuildConfig.DEBUG) {
    myView.setOnClickListener(lClickListener);
}