只要我将minSdkVersion设置为21,一切都很好。但是一旦将其设置为18,我的Macbook Pro(2016)的构建需要18分钟。 尤其是transformForClassesWithDexForFullDebug永远如此。构建API版本18需要很长时间
我的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:[email protected]') {
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实际上在粒度级别上实际上做了什么,这将有助于很多,这将允许我删除导致此疯狂构建时间的那些库依赖关系。有任何想法吗?
API 21的所有目录:各地54秒 – stoefln
对不起@Frank但你解释什么,我已经知道了。我正在寻找解决方案。对于每个构建等待18分钟不是我的选择。 – stoefln
是的,我没有直接的答案。这是一个疯狂的差异。你可以开始检查是否为<21构建生产版本需要很长时间。您可以尝试删除拆分块,以便只创建一个APK。您可以尝试删除jni.srcDirs(为什么它在那里?您是否也在构建本机代码?) – Frank