java - android 的编译速度非常慢(maven,natty)

标签 java android maven dex natty

我正在尝试使用 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/

相关文章:

java - 当所有模块的版本均由单个属性驱动时,构建子模块而不构建父模块

android - 如何将社交身份验证库集成到我的 android studio 项目中

java - 如何将 CSV 导入 Neo4j

Java OpenCV - 使用霍夫变换进行矩形检测

android - 在模块 guava-20.0.jar (com.google.guava :guava:20. 0) 中找到重复的类 com.google.common.util.concurrent.ListenableFuture

android - 处理队列时序列号未知

Android - 第二次打开时显示 Google map v2 或 SupportMapFragment 时出错

java - 为什么 JPA 实体类及其方法不能声明为 final?

java - Jetpack Navigation - 添加 nav_graph.xml 时如何处理依赖警告?

java - VSCode Maven错误 `The compiler compliance specified is 1.7 but a JRE 13 is used`