我有一个多项目(大约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
    }
}

当前回答

在低配置机器上运行Android环境。

关闭浏览器中多余的网页标签 对于防病毒用户,请排除自动生成的build文件夹 Android工作室有1.2 Gb的默认堆可以减少到512 MB 帮助>编辑自定义虚拟机选项 studio.vmoptions -Xmx512m 布局性能将加快 对于Gradle的核心组件之一,在Android工作室Mkae肯定 就像现在3.0beta是最新的版本

以下提示可能会影响代码质量,因此请谨慎使用:

Studio contain Power safe Mode when turned on it will close background operations that lint , code complelitions and so on. You can run manually lintcheck when needed ./gradlew lint Most of are using Android emulators on average it consume 2 GB RAM so if possible use actual Android device these will reduce your resource load on your computer. Alternatively you can reduce the RAM of the emulator and it will automatically reduce the virtual memory consumption on your computer. you can find this in virtual device configuration and advance setting. Gradle offline mode is a feature for bandwidth limited users to disable the downloading of build dependencies. It will reduce the background operation that will help to increase the performance of Android studio. Android studio offers an optimization to compile multiple modules in parallel. On low RAM machines this feature will likely have a negative impact on the performance. You can disable it in the compiler settings dialog.

其他回答

以下是帮助这个刚开始的Android程序员(几年前曾是专业程序员)加速Android Studio 2.2的方法。我知道这是在重复,但是,只是在一个地方总结一下。

初始构建仍然非常缓慢,但现在重新启动运行中的应用程序通常是可以忍受的。我使用的是一台次优PC: AMD四核A8-7410 CPU, 8MB RAM,非ssd HD, Win 10。(这是我第一次在....上发布Stack Overflow;)

在设置-> gradle:

“离线工作”是(这可能是最重要的设置)。

在设置->编译器:

是“并行编译独立模块”(不确定这是否真的有助于利用多核cpu)。

在GRADLE脚本中,“构建。gradle(模块:app)”:

defaultConfig {
    ...
   // keep min high so that restarted apps can be hotswapped...obviously, this is hugely faster.
   minSdkVersion 14
   ...
    // enabling multidex support...does make big difference for me.
    multiDexEnabled true

也在GRADLE脚本,“GRADLE。物业(项目物业)”:

org . gradle。jvmargs=-Xmx3048m -XX: maxpermze =512m -XX:+ heapdumpfdfile -Dfile.encoding=UTF-8

org.gradle.parallel = true org.gradle.daemon = true

此外,在物理设备上而不是模拟器上进行测试对我来说效果很好;可以站立的小平板很方便。

一个微不足道的更改(到一个资源xml)仍然需要10分钟。 正如@rivare在他的回答中所说,命令行构建要快得多(缩短到15秒)。 下面是一些步骤,至少可以从Windows命令行快速完成一个简单的构建。

进入你的项目根目录(gradlew.bat所在的地方): android cd c: \ \ MaskActivity 执行构建: gradlew assembleDebug 直接从手机上卸载apk(拖拽即可卸载)。 构建完成后,使用Windows杀死BIG java进程 任务管理器。

或者如果你的Windows机器上有unix工具:

ps

“pid”的值如下所示:

kill -9 <pid>

现在安装apk: adb -d install C:\Android\MaskActivity\app\build\outputs\apk\app-debug.apk

如果有人正在开发一个通过Subversion进行同步的项目,而且这种情况还在发生,我认为这会减慢Android Studio的工作流程。例如,如果它的工作非常缓慢,而:滚动在一个类,xml等,而我的应用程序仍在我的设备上运行。

在首选项中选择版本控制,并将Subversion设置为None。

您可以尝试打开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/