Android Studio 2.1.2-构建速度太慢

Android Studio 2.1.2-构建速度太慢,android,ubuntu,android-studio,gradle,java-8,Android,Ubuntu,Android Studio,Gradle,Java 8,我有戴尔inspiron N4010笔记本电脑,采用Intel Core i5 CPU M 480@2.67GHz,4GB RAM,500GB硬盘,运行ubuntu 16.04LTS-64位操作系统。我一直在Android Studio 1.5+版本中开发Android应用程序。现在迁移到Android Studio 2.1.2。在我的笔记本电脑的早期版本中,一切都很顺利 在最新版本中构建应用程序太慢;构建需要30秒到1.5分钟-仅在编辑xml文件时。如果我在Java文件中做了任何更改,那么构建

我有戴尔inspiron N4010笔记本电脑,采用Intel Core i5 CPU M 480@2.67GHz,4GB RAM,500GB硬盘,运行ubuntu 16.04LTS-64位操作系统。我一直在Android Studio 1.5+版本中开发Android应用程序。现在迁移到Android Studio 2.1.2。在我的笔记本电脑的早期版本中,一切都很顺利

在最新版本中构建应用程序太慢;构建需要30秒到1.5分钟-仅在编辑xml文件时。如果我在Java文件中做了任何更改,那么构建时间就需要10分钟

所以,我将硬盘格式化为ext4,并完全安装了ubuntu 16.04(单操作系统)-500GB

下载并安装了Android Studio 2.1.2和Oracle jdk 8。不过,每次更改java文件都需要10分钟

这是我的应用程序(模块)渐变文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
        applicationId "com.gmail.balavickey1192"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 300
        versionName "2.0"

        multiDexEnabled true

    }
    dexOptions {
        incremental true
        preDexLibraries true
        javaMaxHeapSize "10g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url 'http://repo.brightcove.com/releases'
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.google.firebase:firebase-core:9.0.0'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'


    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:design:24.0.0'

    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.roughike:bottom-bar:1.4.0.1'
    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.brightcove.player:exoplayer:4.8.2'
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
项目级渐变文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
        applicationId "com.gmail.balavickey1192"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 300
        versionName "2.0"

        multiDexEnabled true

    }
    dexOptions {
        incremental true
        preDexLibraries true
        javaMaxHeapSize "10g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url 'http://repo.brightcove.com/releases'
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.android.gms:play-services:9.0.0'
    compile 'com.google.firebase:firebase-core:9.0.0'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'


    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:design:24.0.0'

    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.roughike:bottom-bar:1.4.0.1'
    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.brightcove.player:exoplayer:4.8.2'
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
我试图从互联网上搜索,并找到了一些解决方案。这是我的gradle.properties文件:

org.gradle.jvmargs=-Xmx11000m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
还禁用了几个插件:

CVS integration
Git
Github
Google cloud tools
Subversion Integration
将以下设置更改为按文件->设置->生成、执行、解聚-->

还是太慢了。。。8到10分钟! 所以决定通过命令行构建;关闭了所有应用程序,包括android studio、firefox和所有应用程序

./gradlew assembleDebug--配置文件--脱机 第一次,它说后续的构建会更快。现在构建时间减少到3到4分钟

以下是生成时生成的报告:

:app    6m47.94s    (total)
:app:transformClassesWithDexForDebug    4m7.32s     
:app:packageDebug   1m24.23s    
:app:mergeDebugJniLibFolders    21.533s     UP-TO-DATE
:app:transformClassesWithMultidexlistForDebug   14.906s     
:app:transformNative_libsWithMergeJniLibsForDebug   10.125s     UP-TO-DATE
:app:compileDebugJavaWithJavac  9.781s  
:app:validateDebugSigning   6.251s  
:app:transformClassesWithJarMergingForDebug     4.309s  
:app:transformResourcesWithMergeJavaResForDebug     3.707s  UP-TO-DATE
:app:zipalignDebug  3.657s  
:app:processDebugJavaRes    0.543s  UP-TO-DATE
:app:mergeDebugResources    0.302s  UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72400Library     0.146s  UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Library  0.121s  UP-TO-DATE
:app:processDebugManifest   0.076s  UP-TO-DATE
:app:generateDebugBuildConfig   0.062s  UP-TO-DATE
:app:processDebugResources  0.061s  UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72400Library  0.054s  UP-TO-DATE
:app:assembleDebug  0.051s  Did No Work
:app:prepareComAndroidSupportMediarouterV72300Library   0.050s  UP-TO-DATE
:app:prepareComFacebookAndroidFacebookAndroidSdk4141Library     0.044s  UP-TO-DATE
:app:prePackageMarkerForDebug   0.041s  
:app:prepareComGoogleAndroidGmsPlayServicesAds900Library    0.041s  UP-TO-DATE

Total Build Time    7m37.73s
Startup     6.695s
Settings and BuildSrc   0.738s
Loading Projects    0.533s
Configuring Projects    10.535s
Task Execution  6m47.94s
这是我通过终端构建gradle时捕获的系统监视器屏幕:

同样的项目在另一台配置相同(i5、4GB内存、500GB硬盘、ubuntu 16.04-64位操作系统)的HP笔记本电脑上顺利运行,工具相同:Android Studio 2.1.2、oracle jdk-8;在这台机器上构建和运行只需几秒钟

但对我来说,整个系统都挂了;从Android Studio或终端构建时无法执行任何操作


伙计们,请帮帮我…

我认为
javaMaxHeapSize“10g”
对于4GB内存来说太大了
javaMaxHeapSize“2g”
可能适合。这是唯一一个需要很长时间构建的应用程序吗?您尝试过其他项目吗?@Dalmas我创建了一个示例应用程序,其构建时间仅为27秒。即使我更改了java文件中的任何内容,构建也只需30秒。如果您的测试设备api高于或等于android L,则激活即时运行。如果您有长时间延迟,则连续构建只需不到20秒的时间检查是否有CPU/光盘/网络活动。如果没有,当gradle试图从服务器/存储库下载一些没有响应的内容时,您可能会遇到网络超时问题。