我有一个多项目(大约10个模块),每次建造大约需要20-30秒。当我在Android Studio中按下Run键时,我每次都要等待重新构建应用程序,这非常缓慢。

是否有可能在Android Studio中自动化构建过程?或者你有什么建议可以加快这个过程吗?

在Eclipse中,由于自动构建,在模拟器上运行相同的项目大约需要3-5秒。

这是我的身材。Gradle文件(app模块):

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':libraries:SharedLibs')
    compile project(':libraries:actionbarsherlock')
    compile project(':libraries:FacebookSDK')
    compile project(':libraries:GooglePlayServices')
    compile project(':libraries:HorizontalGridView')
    compile project(':libraries:ImageViewTouch')
    compile project(':libraries:SlidingMenu')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
    }
}

当前回答

你可以忽略gradle update-to-date检查。

对于运行Android Studio 1.5的Windows:转到文件->设置->构建,执行,部署->构建工具-> Gradle ->检查离线工作(如图所示)

从~30+秒降低到~3秒

其他回答

如果你从命令行使用gradle,你可以让这个过程更快。IDE开发人员有很多优化工作要做。但这只是一个早期版本。

欲了解更多信息,请阅读与一些开发人员在g+上的讨论。

您可以尝试打开studio右侧的gradle菜单,只组装已更改的模块,然后运行install命令。当你按下运行键时,不管你对它正在组装的代码做了什么改变,它都会组装所有东西

到处寻找,终于找到了一个适合我们的解决方案。启用并行构建(在OSX:首选项->编译器-> gradle ->“并行编译独立模块”)和启用“自动制作项目”将它从~1分钟降低到~20秒。感谢/u/Covalence。

http://www.reddit.com/r/androiddev/comments/1k3nb3/gradle_and_android_studio_way_slower_to_build/

你可以忽略gradle update-to-date检查。

对于运行Android Studio 1.5的Windows:转到文件->设置->构建,执行,部署->构建工具-> Gradle ->检查离线工作(如图所示)

从~30+秒降低到~3秒

公认的答案是旧版本的android studio,其中大多数现在仍然有效。更新android studio让它更快了一点。不要费心指定堆大小,因为它会随着Xms和Xmx的增加而自动增加。下面是对VMoptions的一些修改

In bin folder there's a studio.vmoptions file to set the environment configuration. In my case this is studio64.vmoptions Add the following lines if they're not added already and save the file. In my case I've 8GB RAM. -Xms4096m -Xmx4096m -XX:MaxPermSize=2048m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=utf-8` Start android studio. Go to File-> Settings-> Build, Execution, Deployment-> Compiler Check compile independent modules in parallel In command-line Options write: --offline Check Make project automatically Check configure on demand

在使用mac的情况下,起初我找不到vmoptions。不管怎样,这里有一篇关于如何在MAC OSX中更改vmoptions的好文章。引用这篇文章。

打开你的终端,输入下面的命令打开MAC OSX中的vmoptions:

open -e /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions