question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build ignores Kotlin changes with Retrolambda 3.1.0

See original GitHub issue

Here’s a test project: https://github.com/cypressious/KotlinRetrolambdaBug

Run the app. The activity should display “bar”. Now go to com.cypressworks.kotlinretrolambdatest.Foo and change "bar to “foo”. Run the app again. You will see “bar” again.

Gradle prints:

:app:compileDebugKotlin
:app:compileDebugJava UP-TO-DATE
:app:compileRetrolambdaDebug
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE

Notice how, despite compileDebugKotlin and compileRetrolambdaDebug being not up-to-date, the rest of the tasks was skipped?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cypressiouscommented, Aug 21, 2015

Here’s a version of @sfunke’s workaround that’s more generic (works with flavors) and possibly a bit faster:

project.afterEvaluate {
    def variants = project.android.applicationVariants + project.android.testVariants

    variants.each { var ->
        def kotlinTask = tasks["compile${var.name.capitalize()}Kotlin"]

        kotlinTask.doLast {
            println "########"
            println "Dynamically reset compile${var.name.capitalize()}Java's UP-TO-DATE flag"
            println "########"
            tasks["compile${var.name.capitalize()}Java"].outputs.upToDateWhen { false }
        }
    }
}

Seems to also work with JRebel for Android.

EDIT: In version 1.3.0 of the Android Gradle plugin, the task name seems to have changed to compile${var.name.capitalize()}JavaWithJavac.

1reaction
sfunkecommented, Jul 27, 2015

If anyone is interested, my workaround, based on @cypressious 's inspiration and my own limited gradle knowledge. (Just relates to debug build variant, but fits my needs very well.)

I am able to use latest retrolambda gradle plugin (3.2.0)

project.afterEvaluate {
    def tasks = it.tasks
    tasks.each {
        // println "=== afterEvaluate: $it.name"
        if(it.name == "compileDebugKotlin") {
            it.doLast {
                println "########"
                println "Dynamically reset compileDebugJava's UP-TO-DATE flag"
                println "########"
                tasks["compileDebugJava"].outputs.upToDateWhen {false}
            }
        }
    }
}

Explanation: As project is being evaluated, an execution block is added to the compileDebugKotlin task, so whenever that task is run (and our java classes are considered dirty), the compileDebugJava task’s output upToDate-flag is set to false (so compileDebugJava is being forced to run).

Hacky and raw, but gets the job done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android build with retrolambda ignores source code changes
In our project we use gradle + retrolambda + proguard. Retrolambda incremental build is set to false. Sometimes build passes without error but...
Read more >
Realm: Create reactive mobile apps in a fraction of the time
Once you make these two changes, simply refresh your gradle dependencies. ... Dynamic Realm ignores any configured schema, migration, and schema version.
Read more >
Navigation | Android Developers
To generate Java language code suitable for Java or mixed Java and Kotlin modules, add this line to your app or module's build.gradle...
Read more >
Archinamon / android-gradle-aspectj Download - JitPack
Full support of Android product flavors and build types. Support Kotlin, Groovy, Scala and any other languages that compiles into java bytecode.
Read more >
Android Studio 3.1 in stable channel : r/androiddev - Reddit
It seems to work very well without any changes to build process and such. ... I'm getting errors with the 3.1.0 gradle plugin....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found