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分かかります! 依存関係をコンパイルするのが 1 回限りのシナリオであれば問題ありません。しかし、Activity クラスで何かを変更するたびに 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

Java1.6を対象としたライブラリビルドを使用してみてください。-target 15(Java 1.5)でビルドされたjschでも同様の問題が発生し、dxはInnerClassesの古い形式などについて不平を言っています。-targetオプションを指定せずにこのlibを再構築しようとすると、javacはデフォルトで現在のJavaになります。バージョン(おそらく1.6)を作成し、このlibをプロジェクトに配置します。コンパイル時にlibを再構築するためにpom.xmlに配置するmvnオプションを検索しようとしましたが、残念ながら解決策が見つかりませんでした。

于 2013-02-15T11:03:57.157 に答える