我在 Android Studio 中构建需要很长时间,超过 2 分钟,有时 3 分钟。我尝试了 StackOverflow 中介绍的一些方法来加快构建时间,但并没有解决我的问题。
我的 app 模块的 build.gradle 代码如下:
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')
}
我的 gradle.properties 文件如下:
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。这不会很快,特别是取决于您的构建硬件。
如果你想要一个更快的构建,摆脱一些垃圾。例如,有 finer-grained Play Services SDK dependencies一年多;只使用您需要的部分,而不是“除了厨房水槽之外的所有东西”play-services
神器。这反过来可能允许您转储 multidex
,因为您可能会回落到 64K DEX 方法引用限制以下。
Android 工具团队正在努力提高构建速度,这将出现在更新版本的 Android Plugin for Gradle 中。这必须在您的顶级 build.gradle
文件中,因为我看不到您在此处包含的位置。确保您使用的是最新版本,并在新版本发布时不断更新。
关于android - 为什么我的构建需要这么长时间是 Android Studio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33026795/