我正在尝试使用 Natty我的 Android 项目中的 NLP 库。
我已经使用 Maven 在 IntelliJ 中设置了新的 hello world 项目(如 described in this article ;刚刚下载了模板)并将 Natty 添加为依赖项。
public void onCreate(Bundle savedInstanceState)
{
Parser parser = new Parser();
List<DateGroup> groups = parser.parse("two days after christmas at 19");
for (DateGroup group: groups) {
List<Date> dates = group.getDates();
for (Date date: dates) {
Log.e("DATE", date.toString());
}
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
一切似乎都工作得很好,它在适当的时间解析日期......但编译需要将近 5 分钟!如果是一次性场景编译依赖就好了。但是每次我在 Activity 类中更改任何内容都需要 5 分钟。这是 Not Acceptable 。
IntelliJ 表示它花费大部分时间“执行 DEX”。编译输出大量警告信息:
Information:Compilation completed successfully with 41 warnings in 4 min 47 sec
Information:0 errors
Information:41 warnings
Warning:Android Dex: [helloworld] warning: Ignoring InnerClasses attribute for an anonymous inner class
Warning:Android Dex: [helloworld] (org.apache.commons.logging.impl.LogFactoryImpl$1) that doesn't come with an
Warning:Android Dex: [helloworld] associated EnclosingMethod attribute. This class was probably produced by a
Warning:Android Dex: [helloworld] compiler that did not target the modern .class file format. The recommended
Warning:Android Dex: [helloworld] solution is to recompile the class from source, using an up-to-date compiler
Warning:Android Dex: [helloworld] and without specifying any "-target" type options. The consequence of ignoring
Warning:Android Dex: [helloworld] this warning is that reflective operations on this class will incorrectly
Warning:Android Dex: [helloworld] indicate that it is *not* an inner class.
Warning:Android Dex: [helloworld] (org.apache.commons.logging.impl.LogFactoryImpl$2) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.impl.LogFactoryImpl$3) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.impl.SimpleLog$1) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$1) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$2) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$3) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$4) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$5) that doesn't come with an
Warning:Android Dex: [helloworld] (org.apache.commons.logging.LogFactory$6) that doesn't come with an
Warning:Android Dex: [helloworld] (antlr.build.ANTLR$1) that doesn't come with an
Warning:Android Dex: [helloworld] (antlr.debug.misc.ASTFrame$1) that doesn't come with an
Warning:Android Dex: [helloworld] (antlr.TokenStreamRewriteEngine$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.AbstractMap$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.AbstractMap$2) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.Collections$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$2) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$3) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$4) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$5) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.Executors$6) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$2) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$3) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$4) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$5) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$6) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.TimeUnit$7) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.helpers.ThreadHelpers$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.helpers.Utils$1) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.helpers.Utils$2) that doesn't come with an
Warning:Android Dex: [helloworld] (edu.emory.mathcs.backport.java.util.concurrent.locks.FIFOCondVar$1) that doesn't come with an
有什么办法可以加快速度吗?也许 android:dex
不必每次都调用?或者也许有一种方法可以“正确地”编译依赖项?
这是我的pom.xml
文件,如果对您有帮助的话:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>HelloWorld</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>5</maven.compiler.source>
<maven.compiler.target>5</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.joestelmach</groupId>
<artifactId>natty</artifactId>
<version>0.7</version>
</dependency>
</dependencies>
<build>
<!-- This should be just the artifact identifier, no version on the APK file,
because this is what IntelliJ will use by default.
-->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<version>2.6.0</version>
<configuration>
<sdk>
<!-- Don't forget to set your ANDROID_HOME environment variable to your SDK directory! -->
<path>${env.ANDROID_HOME}</path>
<!-- Platform 8 is Android 2.2 -->
<platform>17</platform>
</sdk>
<!-- All of these go into the /src/main/android/ directory, we don't
want to polute the project root directory. -->
<androidManifestFile>${project.basedir}/src/main/android/AndroidManifest.xml</androidManifestFile>
<resourceDirectory>${project.basedir}/src/main/android/res</resourceDirectory>
<assetsDirectory>${project.basedir}/src/main/android/assets</assetsDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/android/native</nativeLibrariesDirectory>
<resourceOverlayDirectory>${project.basedir}/src/main/android/overlay</resourceOverlayDirectory>
<!-- Read the Android Maven plugin documentation about these settings -->
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
最佳答案
尝试使用针对 Java 1.6 的库构建。我对 jsch 有类似的问题,它是用 -target 15 (Java 1.5) 构建的,dx 提示 InnerClasses 旧格式等。你可以尝试重建这个库而不指定 -target 选项,javac 应该默认为你当前的 Java版本(可能是 1.6),然后将此库放入您的项目中。我试图搜索 mvn 选项以放入 pom.xml 以在编译时重建 lib,但不幸的是我还没有找到任何解决方案。
关于java - android 的编译速度非常慢(maven,natty),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14014472/