Android Studio 2.1.2 - 构建速度太慢

时间:2016-08-07 09:40:16

标签: android ubuntu android-studio gradle java-8

我的戴尔inspiron N4010笔记本电脑采用英特尔酷睿i5 CPU M 480 @ 2.67GHz,4GB内存,500GB硬盘运行ubuntu 16.04LTS - 64位操作系统。我一直在Android Studio 1.5+版本中开发Android应用程序。现在已迁移到Android Studio 2.1.2。在我的笔记本电脑中以前版本的AS中,一切都很顺利。

在最新版本中构建应用程序太慢;只需在编辑xml文件时,需要30秒到1.5分钟才能构建。如果我对Java文件进行了任何更改,那么构建时间将达到10分钟。

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

下载并安装了Android Studio 2.1.2和Oracle jdk 8.每次更改任何java文件时,还需要10分钟。

这是我的app(模块)gradle文件:

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'
}

项目级gradle文件:

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

通过文件更改以下设置为选中标记 - >设置 - >构建,执行,部署--->

Global Gradle settings- offline work
Compiler- Compile independent modules
        - Make project automatically
        - command line options: --offline --profile --parallel
        - Use in-process build
        - Configure on demand
Instant run - unchecked(disabled) everything in that tab.

还是太慢了...... 8到10分钟! 因此决定通过命令行构建;关闭每个应用程序甚至Android工作室,Firefox和一切。

  

./ gradlew assembleDebug --profile - 离线   第一次,它说后续构建会更快。现在建造时间缩短到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时捕获的系统监视器屏幕: enter image description here

同样的项目在具有相同配置的另一台HP笔记本电脑上运行顺畅(i5,4GB RAM,500GB HDD,ubuntu 16.04-64位操作系统),相同的工具:Android Studio 2.1.2,oracle jdk-8;只需几秒钟即可在该机器上构建和运行。

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

请帮帮我们......

0 个答案:

没有答案