2

我正在尝试在我的 Android 项目中使用Natty NLP 库。

我已经使用 Maven 在 IntelliJ 中建立了新的 hello world 项目(如本文所述;刚刚下载了模板)并添加了 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 分钟!如果这是编译依赖项的一次性场景,那将是可以的。但是每次我在我的活动课上改变任何东西都需要 5 分钟。这是不可接受的。

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>
4

1 回答 1

1

尝试使用面向 Java 1.6 的库构建。我有类似的 jsch 问题,它是用 -target 15 (Java 1.5) 构建的,dx 抱怨 InnerClasses 旧格式等。你可以尝试在不指定 -target 选项的情况下重建这个库,javac 应该默认为你当前的 Java版本(可能是 1.6),然后将此库放入您的项目中。我试图搜索 mvn 选项以放入 pom.xml 以在编译时重建 lib,但不幸的是我没有找到任何解决方案。

于 2013-02-15T11:03:57.157 回答