通过摇篮和Android Studio的构建和运行应用程序是不是通过Eclipse中慢摇篮、应用程序、Studio、Android

2023-09-11 11:41:06 作者:Traveler^过客

我有一个多项目(〜10个模块),它的建设需要,每次约20-30秒。当我美元的机器人工作室p $ PSS运行,我不得不等待每次来重建应用程序,这是非常缓慢的。

是否有可能实现自动化建设进程,Android的工作室?还是你对如何让这个过程更快什么建议?

在Eclipse中,由于自动建筑,在仿真器上运行同一个项目大约需要3-5秒。

这是我的build.gradle文件(应用模块):

  buildscript {
    库{
        行家{URLhttp://repo1.maven.org/maven2'}
    }
    依赖{
        类路径com.android.tools.build:gradle:0.4
    }
}
应用插件:'机器人'

依赖{
    编译文件树(导演:库,包括:的* .jar)
    编制项目(':库:SharedLibs)
    编制项目(':库:actionbarsherlock)
    编制项目(':库:FacebookSDK)
    编制项目(':库:GooglePlayServices)
    编制项目(':库:Horizo​​ntalGridView)
    编制项目(':库:ImageViewTouch)
    编制项目(':库:SlidingMenu)
}

安卓{
    compileSdkVersion 17
    buildToolsVersion17.0.0

    defaultConfig {
        的minSdkVersion 8
        targetSdkVersion 16
    }
}
 
操作系统当前的配置不能运行此应用程序

解决方案

配置文件

创建一个名为 gradle.properties 中的任何目录适用的文件:

/家庭/<用户名> /摇篮/ (Linux)的 /用户/<用户名> /摇篮/ (苹果机) C:\用户\<用户名> \摇篮(视窗)

附加:

  org.gradle.daemon =真
 

确保您使用了最新开发版本。

命令行参数

- 守护--parallel --offline 的摇篮命令行参数构建工作很大。 了解从文档这些选项。

概述

这是优化的摇篮属性文件( gradle.properties )包括:

 #项目范围的摇篮设置。

#IDE(例如Android的一室公寓)用户:
在该文件中指定#设置将覆盖任何摇篮设置
#通过IDE配置。

#关于如何配置构建环境访问的更多细节
#http://www.gradle.org/docs/current/userguide/build_environment.html

#的摇篮守护进程旨在改善摇篮的启动和执行时间。
#当设置为true的摇篮守护进程是运行版本。
#TODO:在CI关闭后台程序,因为建立应该是干净和可靠的服务器
org.gradle.daemon =真

#指定用于守护进程的JVM参数。
#设置为调整内存设置特别有用。
#默认值:-Xmx10248m -XX:MaxPermSize =256米
org.gradle.jvmargs = -Xmx2048m -XX:MaxPermSize =512米-XX:+ HeapDumpOnOutOfMemoryError -Dfile.encoding = UTF-8

#配置时,摇篮将培养并行模式下运行。
#这个选项只可用于分离项目。更多详细信息,请访问:
#http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel =真

#启用新的孵化模式下配置项目时,让摇篮选择性。
#只有相关项目的配置从而导致更快的构建为大型多项目。
#http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand =真
 

摇篮性质的工作地方,如果你把它们放在 projectRoot \ gradle.properties 和全球范围内,如果你把它们放在 USER_HOME \ .gradle \摇篮。性能。属性如果从控制台摇篮任务或应用直接从理念:

IDE设置

或启用从IDE设置摇篮性能

依赖关系

preFER @aar 的依赖性过库项目。

搜寻AAR包上mavenCentral( http://gradleplease.appspot.com/ ),github上(的 https://github.com/Goddchen/mvn-repo ),或手动从源构建它并投入libs文件夹中。如果您没有编辑的依赖库的来源,你不应该建立它与你的项目源每次。

防病毒

考虑到从防病毒扫描中排除的项目和缓存文件。这显然​​是一个权衡与安全(不要在家里尝试这个!)。但是,如果你分支之间切换了很多,那么杀毒软件就会让摇篮过程中使用它,这会降低建造时间(尤其是AndroidStudio同步项目摇篮文件和索引任务),然后重新扫描文件。测量生成时间和过程的CPU使用和不启用,看它是否是与杀毒软件。

警告

不要使用自动导入功能(但)由于已知的bug,这将的减慢的IDE。

面料Crashlytics

织物具有错字的指向,需要授权的私人行家回购的文档。 http://stackoverflow.com/a/27130652/624706

更多阅读

在摇篮的文章介绍了一些设置,以增加它的速度。

I have a multi-project (~10 modules) of which building takes about 20-30 seconds each time. When I press Run in Android Studio, I have to wait every time to rebuild the app, which is extremely slow.

Is it possible to automate building process in Android Studio? Or do you have any advice on how to make this process faster?

In Eclipse, thanks to automatic building, running the same project on an emulator takes about 3-5 seconds.

This is my build.gradle file (app module):

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

解决方案

Configuration File

Create a file named gradle.properties in whatever directory applies:

/home/<username>/.gradle/ (Linux) /Users/<username>/.gradle/ (Mac) C:\Users\<username>\.gradle (Windows)

Append:

org.gradle.daemon=true

Ensure you are using the latest development versions.

Command Line Arguments

The --daemon --parallel --offline command line arguments for Gradle builds work great. Learn about these options from the documentation.

Overview

An optimized Gradle properties file (gradle.properties) includes:

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
# TODO: disable daemon on CI, since builds should be clean and reliable on servers
org.gradle.daemon=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects. 
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

Gradle properties works local if you place them at projectRoot\gradle.properties and globally if you place them at user_home\.gradle\gradle.properties. Properties applied if you run gradle tasks from console or directly from idea:

IDE Settings

Or enable gradle properties from the IDE settings

Dependencies

Prefer @aar dependencies over library projects.

Search aar package on mavenCentral (http://gradleplease.appspot.com/), github (https://github.com/Goddchen/mvn-repo), or build it manually from sources and put into libs folder. If you are not editing sources of the dependency library you should not build it every time with your project sources.

Antivirus

Consider to exclude project and cache files from antivirus scanning. This is obviously a trade off with security (don't try this at home!). But if you switch between branches a lot, then antivirus will rescan files before allowing gradle process to use it, which slows build time (in particular AndroidStudio sync project with gradle files and indexing tasks). Measure build time and process CPU with and without antivirus enabled to see if it is related.

Warning

Don't use auto-import feature (yet) due to known bug which will slow down the IDE.

Fabric Crashlytics

Fabric has typo at the documentation pointing to the private maven repo which needs authorization. http://stackoverflow.com/a/27130652/624706

More Reading

An article on Gradle describes a few settings to increase its speed.