简体   繁体   English

无法使用Eclipse,Maven和适用于Maven的Android插件编译应用程序

[英]Can't compile an application using Eclipse, Maven, and the Android Plugin for Maven

I'm trying to create an Android application in Eclipse using the Maven plugin and the m2eclipse-android-plugin as well. 我正在尝试使用Maven插件和m2eclipse-android-plugin在Eclipse中创建一个Android应用程序。 Things were going "ok" until recently. 直到最近,事情一直“顺利”。 I'm using Helios on Ubuntu and have the latest JDK (removed the default one installed by Ubuntu). 我在Ubuntu上使用Helios,并具有最新的JDK(已删除Ubuntu所安装的默认JDK)。

The project references two libraries that I've also created. 该项目引用了我也创建的两个库。 One is an Android specific utility project and generates the .apklib (successfully). 一个是Android特定的实用程序项目,并成功生成.apklib。 The other library is a more general purpose set of utilities not specific to Android which produces a JAR file. 另一个库是一组通用用途更广的实用程序,并非专用于生成JAR文件的Android。 Both of these projects are also built using the Maven plugin for Eclipse. 这两个项目都是使用Eclipse的Maven插件构建的。 In addition, I've verified that both the .apklib and .jar files are in the local repository and both included all of the generated class files as would be expected. 另外,我已经验证了.apklib和.jar文件都在本地存储库中,并且都包含了所有预期生成的类文件。

When it goes to build the .apk file, I'm getting a "cannot find symbol" on a class in my Android project where the symbol is a class from the non-Android utility JAR file. 当构建.apk文件时,我在Android项目中的类上收到“找不到符号”,其中该符号是非Android实用程序JAR文件中的类。 For some completely bizarre reason, the class file cannot be found inside the JAR file. 由于某些完全奇怪的原因,无法在JAR文件中找到类文件。 I verified that, in fact, the JAR file is in my local maven repository and that the class file is in the JAR file. 我验证了,实际上,该JAR文件位于我的本地Maven存储库中,并且该类文件位于JAR文件中。 I've also run the maven install command with debugging on, copied the command line that gets fed into the Java compiler. 我还运行了带有调试功能的maven install命令,将命令行复制到了Java编译器中。 When I execute that command in a console, I receive the SAME error (indicating that it's a Java compiler error and not a Maven error). 当我在控制台中执行该命令时,会收到SAME错误(表明这是Java编译器错误而不是Maven错误)。

Has anyone else run into this type of situation before? 有人遇到过这种情况吗? It's extraordinarily strange and I've completely combed the command line for potential issues and, best as I can tell, everything seems correct. 这非常奇怪,我已经完全整理了命令行以解决潜在问题,而且据我所知,一切似乎都是正确的。

Well, through what appears to be trial and error I seem to have fixed the problem. 好吧,通过似乎是反复试验的方法,我似乎已经解决了该问题。 I had a file that looked "similar" to this: 我有一个看起来与此类似的文件:

import Test.TestObserver;
import com.myself.ImportedClassThatCouldntBeFound;

class Test extends ImportedClassThatCouldntBeFound {
  public interface TestObserver {
    public void event ();
  }

  public void addObserver (TestObserver observer) {
    ...
  }
} 

public class AnotherTest {
  private Test test = new Test ();

  public void blah () {
    this.test.addObserver (new TestObserver () {
      public void event () {
        ...
      } 
    });
  }
}

The problem happened at the TOP of the file. 问题发生在文件的TOP。 For some reason, Eclipse imported the inner interface! 由于某种原因,Eclipse导入了内部接口!

When I "REMOVED" that import, and then changed AnotherTest to: 当我“删除”该导入,然后将AnotherTest更改为:

public class AnotherTest {
  private Test test = new Test ();

  public void blah () {
    this.test.addObserver (new Test.TestObserver () {
      public void event () {
        ...
      } 
    });
  }
}

it compiled correctly! 它编译正确! I even verified it by putting the import BACK into the file and removing the fully declared interface name and it caused it to fail again! 我什至通过将导入BACK放到文件中并删除了完全声明的接口名称来进行验证,这导致它再次失败! It's definitely one of the craziest compiler issues I've ever seen and once I get back the FOUR HOURS of my life that I lost researching this, I'll do more investigation into why this is occurring. 毫无疑问,这绝对是我所见过的最疯狂的编译器问题之一,一旦我一生失去了对这四个小时的研究,便会对其发生原因进行更多调查。

This will be the first time I do this on StackOverflow, but I'm going to mark this as the solution because it most definitely was the issue. 这将是我第一次在StackOverflow上执行此操作,但是我将其标记为解决方案,因为这绝对是问题所在。 However, it definitely requires more research (at least on my part) to try and understand what was causing the compiler to become so confused. 但是,它肯定需要更多的研究(至少在我这方面),以尝试了解导致编译器变得如此混乱的原因。

edited this to make it apparent that the class that had the inner interface was extending the class that could not be found when compiled 编辑此代码以使具有内部接口的类扩展为编译时找不到的类

To me, it looks like a problem caused (ultimately) by putting two top-level classes into a single source code file. 在我看来,这似乎是(最终)通过将两个顶级类放入单个源代码文件而引起的问题。 This is generally thought to be bad practice . 通常认为这是不好的做法

It is not clear whether the compilation error is mandated by the JLS, whether it is a bug in the Java compiler. 目前尚不清楚JLS是否规定了编译错误,是否是Java编译器中的错误。 But either way, the best fix is to not put multiple classes into one source file. 但是,无论哪种方式,最好的解决方法是不要将多个类放入一个源文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM