2

I'm trying to use Natty NLP library in my Android project.

I've set up new hello world project in IntelliJ with Maven (as described in this article; just downloaded the template) and added Natty as a dependency.

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);
}

Everything seems to work just fine, it parses dates in decent time... but compilation takes almost 5 minutes! It would be OK if it was one time scenario to compile dependencies. But it takes 5 minutes every time I change anything in my Activity class. Which is unacceptable.

IntelliJ says it spends most time "Executing DEX". Compilation outputs a lot of warning messages:

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

Is there any way to speed things up? Maybe android:dex doesn't have to be invoked every time? Or maybe there is a way to compile dependencies "correct way"?

This is my pom.xml file, if this is helpful:

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

1 Answers1

1

Try to use library build targeted Java 1.6. I've got similar issues with jsch, which is build with -target 15 (Java 1.5), dx is complaining about InnerClasses old format etc. You could try to rebuild this lib without specifying -target option, javac should default to your current Java version (probably 1.6) and then place this lib in your project. I've tried to search mvn option to place into pom.xml to rebuild lib at compile time, but unfortunately I haven't found any solution.

Erdk
  • 11
  • 1
  • If you are asking a user to try something, post it as a comment rather than answer. Thanks anyway for your interest with SO. Good attempt! :) – LGAP Feb 15 '13 at 11:25