始终执行compile gradle任务

时间:2018-02-09 16:30:37

标签: android caching gradle build android-gradle

我有一个minSDK 21的multidex项目,使用gradle 4.5.1和gradle plugin 3.0.1。我的问题是,当我尝试组装和部署到手机时,即使没有任何源文件更改,也会执行编译任务。使用--info时,我会遇到以下原因:

  

任务':app:compileStandardDebugJavaWithJavac'不是最新的,因为:     输入属性'来源'文件C:... \ app \ build \ generated \ source \ buildConfig \ standard \ debug [package] \ BuildConfig.java已更改。     输入属性'来源'文件C:... \ app \ build \ generated \ source \ dataBinding \ standard \ debug \ android \ databinding \ layouts \ DataBindingInfo.java已更改。

您能帮助我找出导致这些文件发生变化并导致重新编译的原因吗?我相信数据绑定源要么在不改变源的情况下改变,要么在编译任务是最新的时候不应该影响。 BuildConfig.java也是如此。

我有gradle缓存,按需配置并启用守护进程。

这是应用build.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 25
        applicationId 'package'

        // for automated testing
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true

        vectorDrawables.useSupportLibrary = true

        buildConfigField "boolean", "PUBLIC_RELEASE", 'false'

    }

    dataBinding {
        enabled true
    }

    lintOptions {
        abortOnError false
    }

    flavorDimensions "tier1"

    productFlavors {
        standard {
            resValue "string", "app_name", "myapp"

            dimension "tier1"
        }
        beta {
            applicationId 'package.beta'

            resValue "string", "app_name", "myapp2"

            dimension "tier1"
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def project = "myapp"
            def separator = "-"
            def flavor = variant.productFlavors[0].name
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def newApkName = project + separator + flavor + separator + buildType + ".apk"
            outputFileName = newApkName
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
        beta {
            aidl.srcDirs = ['src/standard/aidl']
            java.srcDirs = ['src/standard/java']
        }

    }

    signingConfigs {
        buildTypes {
            debug {
                buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
            }
            release {
                buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
            }
        }

    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug_StandardAndBeta
            debuggable true
            buildConfigField "boolean", "CallLogEnabled", "true"
            minifyEnabled false
        }

        release {
            signingConfig signingConfigs.release_StandardAndBeta
            debuggable false //set to true for custom debugable release build
            buildConfigField "boolean", "CallLogEnabled", "false"
            minifyEnabled true //set to false for custom debugable release build
            proguardFiles 'proguard.cfg'
        }
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        disable "NewApi", "RtlCompat", "MissingPermission", "InvalidPackage", "RecyclerView"
        abortOnError false
    }
}


repositories {
    flatDir {
        dirs 'libs'
    }

    // Crashlytics
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {


    // - Google APIs
    implementation('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation('com.google.apis:google-api-services-gmail:v1-rev53-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }

    implementation 'net.openid:appauth:0.4.1'
    implementation 'com.microsoft.graph:msgraph-sdk-android:1.1.+'
    implementation 'net.hockeyapp.android:HockeySDK:4.1.1'

    // DB framework
    implementation 'com.j256.ormlite:ormlite-android:4.48'

    // RX Java
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'io.reactivex:rxjava:1.1.6'

    // HTTP frameworks
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'

    implementation 'com.squareup.picasso:picasso:2.5.2'


    // Google Adwords Tracking
    implementation files('libs/Google/GoogleConversionTrackingSdk-2.2.4.jar')

    // GMS
    implementation 'com.google.android.gms:play-services-analytics:9.0.2'
    implementation 'com.google.android.gms:play-services-gcm:9.0.2'
    implementation 'com.google.android.gms:play-services-identity:9.0.2'
    implementation 'com.google.android.gms:play-services-ads:9.0.2'
    implementation 'com.google.android.gms:play-services-auth:9.0.2'

    // Other dependencies
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:preference-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.code.gson:gson:2.8.+'
    implementation 'com.github.clans:fab:1.6.+'
    implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    implementation 'com.caverock:androidsvg:1.2.2-beta-1'
    implementation 'de.greenrobot:eventbus:2.4.1'
    implementation 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    implementation 'com.facebook.device.yearclass:yearclass:1.0.+'
    implementation 'com.facebook.android:facebook-android-sdk:4.15.0'
    implementation 'org.parceler:parceler-api:1.1.9'
    annotationProcessor 'org.parceler:parceler:1.1.9'

    // Android architecture components
    implementation "android.arch.lifecycle:extensions:1.0.0"
}

1 个答案:

答案 0 :(得分:3)

这是因为you're using a buildConfigFieldSystem.currentTimeMillis()。此行导致BuildConfig类更新为调试版本:

  

buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"

Android Gradle Plugin每次进行构建时都会更新BuildConfig.java并插入当前日期,生成类似于此的静态字段:

public static final java.util.Date buildTime = new java.util.Date(1518194256644L);

由于时间一直在变化(哈哈),因此必须重新编译文件。