只要我将minSdkVersion设置为21,一切都很好。但是一旦我将它设置为18,我的Macbook Pro(2016)上的构建需要18分钟。 特别是transformClassesWithDexForFullDebug就像永远一样。
我的构建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'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId “my.android.app”
//Todo: change to 18 for final export. Having minSdkVersion 21 reduces build time significantly
minSdkVersion 18
targetSdkVersion 25
versionCode 6
versionName "0.5.1"
testInstrumentationRunner "my.android.app.MockTestRunner"
setProperty("archivesBaseName", “MyApp-v$versionName")
multiDexEnabled true
// externalNativeBuild {
// ndk {
// abiFilters "armeabi-v7a", "x86"
// }
// }
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
debug{
// Disable fabric build ID generation for debug builds
ext.enableCrashlytics = false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
demo {
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
resValue "string", "app_name", “Appname Demo"
}
full {
resValue "string", "app_name", “Appname”
}
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk false
}
}
// externalNativeBuild {
// ndkBuild {
// path "src/main/jni/Android.mk"
// }
// }
}
repositories {
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven{
url 'https://maven.fabric.io/public'
}
}
dependencies {
def supportLibVersion = '25.3.1'
def playServicesVersion = '10.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
//Utils
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex.rxjava2:rxjava:2.0.9'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.birbit:android-priority-jobqueue:2.0.1'
compile "com.google.android.gms:play-services-gcm:$playServicesVersion"
compile "com.google.android.gms:play-services-vision:$playServicesVersion"
//UI
compile "com.android.support:support-dynamic-animation:$supportLibVersion"
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile "com.android.support:recyclerview-v7:$supportLibVersion"
compile 'io.realm:android-adapters:2.0.0'
compile 'com.commit451:PhotoView:1.2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
//Used to create Picasso instance wrapping a custom OkHttp client for testing
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
//API calls
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.okhttp3:okhttp:3.4.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.0'
//Views injection
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile "com.android.support:support-annotations:$supportLibVersion"
//Analytics
compile "com.mixpanel.android:mixpanel-android:5.+"
compile "com.google.android.gms:play-services:$playServicesVersion"
//Crash reporting
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
//Debug database
debugCompile 'com.facebook.stetho:stetho:1.5.0'
debugCompile 'com.uphyca:stetho_realm:2.0.0'
//Testing
androidTestCompile "com.android.support:support-annotations:$supportLibVersion"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//For recyclerview actions
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
// Necessary to avoid version conflicts
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
testCompile 'junit:junit:4.12'
//Mockito and other dependencies to mock api calls
androidTestCompile 'org.mockito:mockito-core:2.0.2-beta'
androidTestCompile "com.crittercism.dexmaker:dexmaker:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:1.4"
//Library that allows waiting for retrofit calls with espresso
androidTestCompile ('com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'){
exclude module: 'okhttp'
}
androidTestCompile 'com.android.support.test:runner:0.5'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.5'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'com.linkedin.testbutler:test-butler-library:1.3.1'
}
我正在寻找一种方法将编译时间缩短到最多5分钟。我的猜测是,如果我能弄清楚transformClassesWithDexForFullDebug实际上在粒度级别上真正做了什么会有很大帮助,这将允许我删除那些导致这种疯狂构建时间的库依赖项。有什么想法吗?
答案 0 :(得分:0)
这是一个常见问题,也是许多开发人员使用minSdkVersion 21进行调试构建的原因。我自己有两个productFlavors,一个有minSdkVersion 15,另一个有21个。我使用minSdkVersion 21进行日常工作,因为它的构建速度比API 15快得多.18分钟是极端的,你的是什么在API 21上建立时间?
另见:https://developer.android.com/studio/build/optimize-your-build.html "开发应用时,应尽可能部署到运行Android 7.0(API级别24)或更高版本的设备。"
答案 1 :(得分:0)
我设法通过删除〜/ .gradle /
中的所有目录将构建时间缩短到2.5分钟rm -rf ~/.gradle/