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

时间:2022-09-30 17:14:33

I'm trying to create an Android application in Eclipse using the Maven plugin and the m2eclipse-android-plugin as well. Things were going "ok" until recently. I'm using Helios on Ubuntu and have the latest JDK (removed the default one installed by Ubuntu).

我正在尝试使用Maven插件和m2eclipse-android-plugin在Eclipse中创建一个Android应用程序。直到最近,事情才“好”。我在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). The other library is a more general purpose set of utilities not specific to Android which produces a JAR file. Both of these projects are also built using the Maven plugin for Eclipse. 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.

该项目引用了我也创建的两个库。一个是Android特定的实用程序项目,并生成.apklib(成功)。另一个库是一组更通用的实用程序,不是特定于Android的,它生成一个JAR文件。这两个项目也都是使用Eclipse的Maven插件构建的。另外,我已经验证了.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. For some completely bizarre reason, the class file cannot be found inside the JAR file. I verified that, in fact, the JAR file is in my local maven repository and that the class file is in the JAR file. I've also run the maven install command with debugging on, copied the command line that gets fed into the Java compiler. 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).

当它构建.apk文件时,我在Android项目中的类上找到了“找不到符号”,其中符号是来自非Android实用程序JAR文件的类。由于某些完全奇怪的原因,在JAR文件中找不到类文件。事实上,我验证了JAR文件位于我的本地maven存储库中,并且该类文件位于JAR文件中。我还运行带有调试功能的maven install命令,复制了输入Java编译器的命令行。当我在控制台中执行该命令时,我收到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.

以前有没有其他人遇到这种情况?这是非常奇怪的,我已经完全梳理了命令行中的潜在问题,而且,正如我所知,一切似乎都是正确的。

2 个解决方案

#1


0  

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. 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! 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.

它编译正确!我甚至通过将导入BACK放入文件并删除完全声明的接口名称来验证它,这导致它再次失败!这绝对是我见过的最疯狂的编译器问题之一,一旦我回到生命中的四个小时,我就失去了研究这个问题,我会更多地调查为什么会发生这种情况。

This will be the first time I do this on *, but I'm going to mark this as the solution because it most definitely was the issue. 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

对此进行了编辑,使得具有内部接口的类显然扩展了编译时无法找到的类

#2


0  

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. But either way, the best fix is to not put multiple classes into one source file.

目前尚不清楚JLS是否强制要求编译错误,是否是Java编译器中的错误。但无论哪种方式,最好的解决方法是不要将多个类放入一个源文件中。

#1


0  

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. 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! 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.

它编译正确!我甚至通过将导入BACK放入文件并删除完全声明的接口名称来验证它,这导致它再次失败!这绝对是我见过的最疯狂的编译器问题之一,一旦我回到生命中的四个小时,我就失去了研究这个问题,我会更多地调查为什么会发生这种情况。

This will be the first time I do this on *, but I'm going to mark this as the solution because it most definitely was the issue. 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

对此进行了编辑,使得具有内部接口的类显然扩展了编译时无法找到的类

#2


0  

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. But either way, the best fix is to not put multiple classes into one source file.

目前尚不清楚JLS是否强制要求编译错误,是否是Java编译器中的错误。但无论哪种方式,最好的解决方法是不要将多个类放入一个源文件中。