androidjavaの実装がsunjavaの実装とは異なるという事実と、Mavenのビルド中にベースJavaクラスがクラスパスに(最後まで)含まれているという事実の両方が原因で、かなり奇妙な問題が発生しています。アンドロイドプロジェクト。解決策はクラスパスにJavaクラスを持たないことだと思いますが、これを行う方法を見つけることができないようです。
基本的に、java.util.concurrent(androidとjavaの両方)にAbstractExecutorServiceというクラスがあります。javaクラスには、Androidで使用したいnewTaskForというメソッドがいくつか含まれていますが、Androidの実装にはそれらがありません。問題ありません。実装するだけです(RunnableFutureの代わりにFutureを使用するなど、いくつかの変更を加えます)。これはant(移行元のビルドツール)では正常に機能します。
問題は、mavenがクラス(AbstractExecutorServiceを拡張する)をコンパイルしようとすると、メソッドが見つからないときにAndroid実装にメソッドを追加するのではなく、クラスパスを続行し、Javaメソッドを見つけて、タイプが一致しません。理想的には、Androidのビルド中にJavaクラスが利用可能になるべきではないと思います。なぜなら、Javaクラスでできることは、実際には実行できないメソッドを実行できると思わせることだけですが、現在、あらゆる種類の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:これは新しいコードではないことにも注意する必要があります。それは1年以上前のものであり、それ以来antを使用して完全にコンパイルされています。これは、多数の安定したリリースの一部です。現在、ビルドプロセスをMavenに移行している最中なので、このパッケージを正しくビルドするようにセットアップしようとしています。