在 maven android 构建期间,基础 java 类仍在类路径中

2024-01-09

我遇到了一个相当奇怪的问题,原因是 android java 实现与 sun java 实现不同,并且在 Maven 构建期间,基本 java 类仍然包含在类路径中(一直到最后)安卓项目。我认为解决方案是不在类路径上包含 java 类,但我似乎找不到方法来做到这一点。

基本上,java.util.concurrent中有一个名为AbstractExecutorService的类(在android和java中)。 java 类包含几个名为 newTaskFor 的方法,我想在 android 中使用它们,但 android 实现没有它们。没问题,我将实现它们(进行一些更改,例如使用 Future 而不是 RunnableFuture)。这在 ant(我们正在迁移的构建工具)中工作得很好。

问题是,当maven尝试编译我的类(它扩展了AbstractExecutorService)时,它不是在找不到它们时将我的方法添加到android实现中,而是继续沿着类路径,找到java方法并抱怨返回类型不匹配。理想情况下,我认为 java 类在 android 构建期间甚至不应该可用,因为它们所能做的就是让你认为你可以运行你实际上不能运行的方法,但目前你可以运行各种 java 方法,而不是在 android 中可用,它将编译良好(在 Maven 中)。

有人对此有什么建议或解决方案吗?有人遇到过类似的事情吗?



编辑:这是 pom 的相关部分(省略了存储库等):

<dependencies>
    <dependency>
        <groupId>org.beanshell</groupId>
        <artifactId>bsh</artifactId>
        <version>2.0b5</version>
        <optional>true</optional>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <optional>true</optional>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android-with-java</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.byteman</groupId>
        <artifactId>byteman-bmunit</artifactId>
        <version>2.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>bouncycastle</groupId>
        <artifactId>bcprov-jdk15</artifactId>
        <version>140</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>conf</directory>
            <includes>
                <include>*.xml</include>
            </includes>
            <excludes>
                <exclude>*-service.xml</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>${project.build.directory}/schema</directory>
        </resource>
        <resource>
           <directory>${project.basedir}</directory>
           <includes>
              <include>INSTALL.html</include>
              <include>LICENSE</include>
              <include>README</include>
           </includes>
        </resource>
        <resource>
          <directory>${project.basedir}/lib</directory>
          <includes>
             <include>licenses/thirdparty*</include>
          </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <excludes>
                    <exclude>stuff/stuff/util/JUnitXMLReporter.java</exclude>
                </excludes>
            </configuration>
        </plugin>
       <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <version>1.7</version>
          <executions>
             <execution>
                <id>add-source</id>
                <phase>validate</phase>
                <goals>
                   <goal>add-source</goal>
                </goals>
                <configuration>
                   <sources>
                      <source>target/generated-sources</source>
                   </sources>
                </configuration>
             </execution>
             <execution>
                <id>add-test-source</id>
                <phase>validate</phase>
                <goals>
                   <goal>add-test-source</goal>
                </goals>
             </execution>
          </executions>
       </plugin>
       <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <phase>process-resources</phase>
                  <configuration>
                    <tasks>
                        <echo>Precompiling magic ids and protocol ids</echo>    
                        <xslt in="conf/stuff.xml" out="target/generated-sources/stuff/stuff/ClassMagicEncoding.java"
                            style="conf/stuff.xslt">
                            <param name="type" expression="Magic"/>
                        </xslt>
                        <xslt in="conf/stuff.xml" out="target/generated-sources/stuff/stuff/ClassProtocolEncoding.java"
                            style="conf/stuff.xslt">
                            <param name="type" expression="Protocol"/>
                        </xslt>
                    </tasks>
                  </configuration>
                </execution>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <property name="compile_classpath" refid="maven.compile.classpath"/>
                            <property name="plugin_classpath" refid="maven.plugin.classpath"/>
                            <delete dir="${project.build.directory}/schema" failonerror="false"/>
                            <mkdir dir="${project.build.directory}/schema"/>
                            <java classname="stuff.stuff.util.XMLSchemaGenerator">
                                <classpath>
                                    <pathelement path="${compile_classpath}"/>
                                    <pathelement path="${plugin_classpath}"/>
                                </classpath>
                                <arg line="-o ${project.build.directory}/schema"/>
                            </java>
                        </tasks>
                    </configuration>
                </execution>
            </executions>

            <configuration>
                <!-- prints the classpath to ensure correct jars are available -->
                <tasks>
                            <property name="compile_classpath" refid="maven.compile.classpath"/>
                    <echo>rawr=${compile_classpath}</echo>
                    <echo>java.class.path=${java.class.path}</echo>
                    <echo>CLASSPATH=${env.CLASSPATH}</echo>
                </tasks>
            </configuration>

            <dependencies>
                <dependency>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                    <version>2.7.1</version>
                </dependency>
                <dependency>
                    <groupId>xalan</groupId>
                    <artifactId>serializer</artifactId>
                    <version>2.7.1</version>
                </dependency>
                <dependency>
                    <groupId>ant</groupId>
                    <artifactId>ant-antlr</artifactId>
                    <version>1.6.5</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-nodeps</artifactId>
                    <version>1.8.1</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Main-Class>stuff.stuff.Version</Main-Class>
                    <Implementation-Version>${project.version}</Implementation-Version>
                    <Export-Package>
                        schema;version=${project.version},
                        ${project.groupId}.*;version=${project.version}
                    </Export-Package>
                    <Bundle-RequiredExecutionEnvironment>J2SE-1.6</Bundle-RequiredExecutionEnvironment>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.2.0</version>
            <extensions>true</extensions>
                <configuration>
                    <sdk>
                         <platform>8</platform>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
        </plugin>
    </plugins>
</build>





Edit2:这是我收到的编译错误。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mystuff: Compilation failure: Compilation failure:
[ERROR] /home/stuff/stuff/ExecutionService.java:[775,28] <T>newTaskFor(java.lang.Runnable,T) in stuff.ExecutionService cannot override <T>newTaskFor(java.lang.Runnable,T) in java.util.concurrent.AbstractExecutorService; attempting to use incompatible return type
[ERROR] found   : java.util.concurrent.Future<T>
[ERROR] required: java.util.concurrent.RunnableFuture<T>
[ERROR] /home/stuff/ExecutionService.java:[791,28] <T>newTaskFor(java.util.concurrent.Callable<T>) in stuff.ExecutionService cannot override <T>newTaskFor(java.util.concurrent.Callable<T>) in java.util.concurrent.AbstractExecutorService; attempting to use incompatible return type
[ERROR] found   : java.util.concurrent.Future<T>
[ERROR] required: java.util.concurrent.RunnableFuture<T>
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mystuff: Compilation failure

注意:ExecutionService 是继承 AbstractExecutorService 的类。但是,我希望它仅扩展 android 版本而不是基本 java 版本。我什至尝试将 newTaskFor 的存根方法插入到 Android 版本的 AbstractExecutorService 中(认为编译器应该假设我重写这些方法而不是基本的 java 方法 - 尽管我应该注意到代码中没有 @Override )但它仍然不起作用。

没有人要求它们,但这是我的方法声明:

protected <T> Future<T> newTaskFor(Runnable runnable, T value) 
{
//stuff
}

protected <T> Future<T> newTaskFor(Callable<T> callable) 
{
//stuff
{

我目前的理论是,它与模板类型有关,但我不太确定如何证明或修复它。

6/30 编辑:我还应该注意的是,这是not新代码。它已经存在一年多了,并且从那时起就一直使用 ant 完美编译。它已成为许多稳定版本的一部分。我们现在正在将构建过程迁移到 Maven,因此我正在尝试将此包设置为正确构建。


问题是 Maven 自动在类路径上包含 Oracle JDK,并且 Android jar 提供了这些的替代实现,并且它们有时会有所不同。在这个阶段,我不知道是否可以告诉 Maven 编译器插件从其类路径中删除 JDK,而只使用类路径上的依赖项。恕我直言,这将解决问题。

请在 Android Maven 插件问题跟踪器中创建一个问题,并可能通过询问 Maven 用户或开发人员列表来进行调查。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 maven android 构建期间,基础 java 类仍在类路径中 的相关文章

随机推荐

  • Python 中无法连接字符串和整数的原因[重复]

    这个问题在这里已经有答案了 大量文献记载了这一点str需要先将整数转换为字符串 然后才能连接它们 I am str n years old Python不允许一定有根本原因 I am n years old 我想知道原因是什么 在我的项目中
  • 函数到函数指针的“衰减”

    我们知道一个参数看起来像void 将被重写为void 这类似于数组到指针的衰减 其中int 变成int 在很多情况下 使用数组会将其衰减为指针 除了参数之外 是否存在函数 衰减 的情况 C 标准规定 8 3 5 5 确定各个参数的类型后 任
  • 将 x 轴标签放置在句点刻度之间

    我想将 x 轴标签放置在刻度之间 For example by default R produces a graph that looks like this Note I added axis 1 c 2001 2002 2003 200
  • 带倒计时器的 QMessageBox

    我想知道向倒计时器添加倒计时器的最佳方法是什么QMessageBox 例如 当显示消息框时 倒计时器会启动 例如 5 秒 如果用户没有响应消息框 消息框将选择默认选项 像这样的事情怎么样 include
  • C++ - 从 std::string 类派生类以添加额外的功能?

    首先 我知道std string类具有我可能需要的所有功能 这只是为了测试目的 看看我将来能做什么 反正 说我有这个 class MyString public std string 例如 我将如何使用 MyString varName w
  • 用 C++ 编写 MIDI 文件

    您好 我在寻找有关此问题的正确信息时遇到一些问题 如果有人能指出正确的方向 我会很高兴 如何编码 midi 文件 例如我怎样才能编写一个播放随机音调 1 秒的片段 基本上我需要完成的是将不同的 midi 旋律表示为某种向量 我怎样才能做到这
  • 这种向量删除方法有什么问题吗?

    我有一个有效的删除方法 如下 void deleteUserByID int id std vector
  • 更新后 Gradle 错误:com.android.tools:sdk-common

    我将 Android Studio 更新到最新版本 3 1 Canary 8 并强制将 com android tools build gradle 更新到版本 3 1 0 alpha08 但同步项目时出现此错误 Could not fin
  • 无法 insmod 或使用内核间模块

    我在内核驱动程序 1 KD1 ko 中有一个函数 static void test void EXPORT SYMBOL test static void test printk lt lt lt MISSION DONE gt gt gt
  • 使用 Android 导航组件获取 Backstack 状态

    我想实现后压行为 以便当您在后退堆栈为空时按后退时提示确认弹出窗口 否则它会弹出堆栈中的下一个片段 我试图获取后退堆栈计数 但我总是从两个片段管理器中得到 0 getSupportFragmentManager getBackStackEn
  • 将 ISO 8601 日期转换为标准字符串格式

    我正在尝试转换一个有效的ISO 8601 http en wikipedia org wiki ISO 8601字符串转换为一致的格式 以便可以使用简单的字典顺序进行排序和搜索 我的应用程序可以接收以下任意格式的日期 时间 例如 2015
  • 检测 Android 应用程序是从 Google Play 下载还是从 Amazon 下载还是从其他地方下载

    我知道这可能不太可能 但有没有什么方法可以以编程方式检测应用程序是否托管在 Amazon 应用商店和 Google Play 上 我想链接到下载该应用程序的应用程序商店 并且如果可以避免的话 我不想有两个不同的 APK 仅具有这种差异 截至
  • Xcode 引用框架而不是链接二进制文件与库

    在开发可可触摸框架时 我如何通过引用第三方框架中的代码来使用它 然后将其包含在 链接二进制文件与库 选项中 我不想链接到二进制文件 以防止托管项目和框架 将使用该框架的项目 之间的符号冲突 此外 我需要框架代码来使用托管项目对第三方框架的引
  • 在 Windows 中哪里可以找到“dnu”命令

    我最近安装了 Visual Studio 2015 RC 我正在尝试找出新的 NET Core 东西 现在我想打包我的应用程序并启动它 我想使用 DNX Utility 但不知道如何运行它 我的命令提示符仍然坚持没有dnu命令说 dnu i
  • 在 JavaScript 中连接十六进制字节和字符串,同时保留字节

    我想使用 JavaScript 连接一个十六进制值和一个字符串 var hexValue 0x89 var png PNG 字符串 PNG 相当于串联0x50 0x4E and 0x47 连接hexValue and png via var
  • 如果我将 .on('click' 事件附加到 $("body") 上,性能是否会受到影响?

    我目前有以下代码 loginLink registerLink click function dialog this return false detailData on click modalDeleteLink modalEditLin
  • Axapta 2009 X++ 从网站下载文本文件

    我想从网站下载一个文本文件 因为我知道它的 URL 有几个例子在Axaptapedia com 加载网络文档 http www axaptapedia com Load Web Documents 这些示例使用 Microsoft NET
  • 在docker容器中为php启用soap

    我无法让肥皂与我的 php Docker 设置一起工作 我正在使用适用于 Windows 版本 18 03 1 ce win65 17513 的 Docker CE PHP 版本 7 2 3 我尝试从容器内部运行apt get instal
  • 如何在 docker compose Secret 中使用主目录中的文件?

    我正在尝试构建一个包含私有节点包的 docker 容器 我已关注本指南 https www alexandraulsh com 2019 02 24 docker build secrets and npmrc 使用密钥安全地引用 npmr
  • 在 maven android 构建期间,基础 java 类仍在类路径中

    我遇到了一个相当奇怪的问题 原因是 android java 实现与 sun java 实现不同 并且在 Maven 构建期间 基本 java 类仍然包含在类路径中 一直到最后 安卓项目 我认为解决方案是不在类路径上包含 java 类 但我