Android 为什么我的构建需要这么长的时间?
我的构建在Android Studio中需要很长时间,超过2分钟,有时3分钟。我尝试了StackOverflow中解释的一些方法来加快构建时间,但没有解决我的问题 应用程序模块的My build.gradle代码如下:Android 为什么我的构建需要这么长的时间?,android,android-studio,gradle,build,Android,Android Studio,Gradle,Build,我的构建在Android Studio中需要很长时间,超过2分钟,有时3分钟。我尝试了StackOverflow中解释的一些方法来加快构建时间,但没有解决我的问题 应用程序模块的My build.gradle代码如下: buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabr
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
// Adding The GIT SHA to Crashlytics crash reporting
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.moymer"
minSdkVersion 11
targetSdkVersion 22
multiDexEnabled true
versionCode 5
versionName "2.0.0"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.github.nirhart:parallaxscroll:1.0'
compile 'com.android.support:multidex:1.0.0'
compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
transitive = true;
}
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'com.android.support:recyclerview-v7:23+'
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:percent:23.0.0'
compile 'com.jakewharton.timber:timber:3.1.0'
compile project(':androidffmpeglibrary')
}
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
我的gradle.properties文件如下所示:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
// Adding The GIT SHA to Crashlytics crash reporting
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.moymer"
minSdkVersion 11
targetSdkVersion 22
multiDexEnabled true
versionCode 5
versionName "2.0.0"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.github.nirhart:parallaxscroll:1.0'
compile 'com.android.support:multidex:1.0.0'
compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
transitive = true;
}
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'com.android.support:recyclerview-v7:23+'
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:percent:23.0.0'
compile 'com.jakewharton.timber:timber:3.1.0'
compile project(':androidffmpeglibrary')
}
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
你有11个以上的依赖项和一个额外的插件。至少有一个(
androidffmpeglibrary
)可能涉及NDK。这不会很快,尤其取决于构建硬件
如果你想要一个更快的构建,去掉一些垃圾。例如,一年多来,;只使用你需要的部分,而不是“除了厨房水槽以外的所有东西”play services
artifact。这反过来可能允许您转储multidex
,因为您可能会回落到64K DEX方法引用限制以下
Android工具团队正在努力提高构建速度,这将在Gradle的新版Android插件中体现出来。这必须在您的顶级
build.gradle
文件中,因为我看不出您在哪里包含它。确保您使用的是最新版本,并在新版本发布时不断更新。正如Commonware所描述的,有很多依赖项确实会降低整个构建的速度。现在,你可以开始使用Android Studio 2.0了,它有这个功能
即时运行大大缩短了构建时间,因为它只推动了不需要的小更改。无论您在代码中做了什么更改,都首先分为三类:热交换、热交换和冷交换。负载越小,交换越热,构建时间越快
大的结构变化,如更改注释、静态字段等,将进入冷交换。清单文件中的更改也在冷交换中进行。你可以查看完整的列表
好消息是,大多数小的更改都是在热插拔中进行的,只要您按下run按钮,这些更改就会在正在运行的应用程序中快速进行。相关活动将重新启动,您可以在几秒钟内看到所做的更改
Android Studio 2.0的稳定版本已经发布,您可以下载它。它有这个即时运行功能。希望这有帮助