Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks fail in a project using version 4.0.0 of the Android Gradle Plugin #106

Open
jschear opened this issue Jun 12, 2020 · 8 comments · May be fixed by #118
Open

Tasks fail in a project using version 4.0.0 of the Android Gradle Plugin #106

jschear opened this issue Jun 12, 2020 · 8 comments · May be fixed by #118

Comments

@jschear
Copy link
Contributor

jschear commented Jun 12, 2020

After upgrading to AGP 4.0.0, our clear<variant>OkReplayTapes task is failing with a NoClassDefFoundError. It looks like ConnectedDeviceProvider was moved to the com.android.build.gradle.internal.testing package.

I tried upgrading the AGP dependency in OkReplay, but it's going to take a bit of work -- it requires Gradle 6.1.1 at a minimum, but https://github.com/groovy/groovy-android-gradle-plugin isn't compatible with Gradle 6 (and it is no longer maintained), so the tests in the okreplay-tests project will probably need to be migrated to Java or Kotlin.

I think the best move here is to access the device providers through AGP'sBaseExtension#deviceProviders API instead of instantiating them directly, which looks like it should work on AGP 3.6.0 and 4.0.0. I'm working on a PR to do that.

Stacktrace:

jschear ~/dev/slack-android-ng (master) $ ./gradlew app:clearInternalDebugOkReplayTapes --stacktrace
> Task :app:clearInternalDebugOkReplayTapes FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:clearInternalDebugOkReplayTapes'.
> com/android/builder/testing/ConnectedDeviceProvider

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:clearInternalDebugOkReplayTapes'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:207)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:205)
        ...
Caused by: java.lang.NoClassDefFoundError: com/android/builder/testing/ConnectedDeviceProvider
        at okreplay.DeviceBridge.<init>(DeviceBridge.kt:10)
        at okreplay.DeviceBridgeProvider$Companion.get$okreplay_gradle_plugin(DeviceBridgeProvider.kt:15)
        at okreplay.ClearTapesTask.clearTapes$okreplay_gradle_plugin(ClearTapesTask.kt:16)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
        ...
@stopdrake
Copy link

Hey @jschear. We are facing this same problem after upgrading to AGP 4.0.0 . Were you able to solve this or have a workaround?

@jschear
Copy link
Contributor Author

jschear commented Jul 16, 2020

Unfortunately I haven't -- I actually stopped using OkReplay for separate reasons soon after this issue popped up. I think I have a pretty good idea of what needs to be done to fix this issue, though (adopting the BaseExtension#deviceProviders API), and I may have some time this weekend to work on a PR.

@jschear
Copy link
Contributor Author

jschear commented Sep 11, 2020

I think I was wrong about moving to the BaseExtension#deviceProviders being a solution -- that function returns an empty list when I test locally, and it appears to be an extension point for adding other, custom DeviceProviders.

I see a few ways forward here:

  • Do some sort of reflection to load the DeviceProvider class from the correct package depending on the version of AGP that's on the classpath.
  • Copy ConnectedDeviceProvider into okreplay's source tree and call it a day.

@felipecsl, @rossbacher do either of you have an opinion here?

@rajab57
Copy link

rajab57 commented Jan 4, 2021

Is this issue resolved ? I am encountering similar issue.
I am exploring okreplay to use in my project at this point.

@stopdrake
Copy link

stopdrake commented Jan 6, 2021

For anyone who might want to use OKReplay in there project with AGP >= 4.0 I followed @jschear steps but instead of fixing the okreplay-tests for reasons mentioned by him I removed that module from settings.gradle while building.

Please note this is not an official solution and something I did to get it working in my project.
You can find the gist here - https://gist.github.com/stopdrake/0e6607d4a12112d1909320eacf5245cc

Steps to run

  1. Copy the jar file to a gradleLibs or libs directory inside your module
  2. In your module level build.gradle add classpath to your buildscript dependencies like below
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
//      classpath "com.airbnb.okreplay:gradle-plugin:$okreplay_gradle"
        classpath files('gradleLibs/okreplay-gradle-plugin-1.6.0.jar')
    }
}

@mfekim
Copy link

mfekim commented Jan 19, 2021

Like @rajab57, I would like to use OkReplay, but it's not working with AGP >= 4.0 :(

The @stopdrake's solution seems to work but it would be nice if you can fix it

@KatieBarnett
Copy link

The above workaround seems to have stopped working, I now get this error:

Execution failed for task ':app:clear<variant>OkReplayTapes'.
> 'void com.android.build.gradle.internal.testing.ConnectedDeviceProvider.<init>(java.io.File, int, com.android.utils.ILogger)'

I am using the following versions:
OkReplay: 1.6.0 (both workaround, and official version)
AGP: 7.1.0-alpha05
AndroidX Test: 1.4.0
Espresso: 3.4.0

@KatieBarnett
Copy link

KatieBarnett commented Mar 14, 2022

I have also tried the above and get the same error with:
OkReplay: 1.6.0 (both workaround, and official version)
AGP: 7.1.2
AndroidX Test: 1.4.0
Espresso: 3.4.0

Please fix this as it is holding our project up from upgrading the gradle plugin.

@randallnwf randallnwf linked a pull request Mar 17, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants