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

Error while trying to run android tests with proguarded debug build #70

Closed
juliocbcotta opened this issue Aug 19, 2021 · 6 comments
Closed

Comments

@juliocbcotta
Copy link

Hello there, I am using Flank to run UI Tests on Firebase Test Lab, and when I run proguard over my build I get this error that seems related to this library.

I am using AGP 4.4.2. I tried to create a minimal repro project, but I couldn't.
Would you have any ideas of what can be happening ?

RunTests

java.nio.BufferUnderflowException
        at java.base/java.nio.Buffer.nextGetIndex(Buffer.java:650)
        at java.base/java.nio.HeapByteBuffer.getInt(HeapByteBuffer.java:400)
        at com.linkedin.dex.spec.AnnotationOffItem.<init>(AnnotationOffItem.kt:13)
        at com.linkedin.dex.spec.AnnotationSetItem$Companion.create(AnnotationSetItem.kt:18)
        at com.linkedin.dex.parser.AnnotationUtilsKt.checkIfAnnotationIsInherited(AnnotationUtils.kt:89)
        at com.linkedin.dex.parser.AnnotationUtilsKt.getTestAnnotation(AnnotationUtils.kt:77)
        at com.linkedin.dex.parser.AnnotationUtilsKt.getClassAnnotationValues(AnnotationUtils.kt:46)
Total run duration: 0m 10s
        - Preparation: 0m 7s
        at ftl.run.platform.android.CreateAndroidTestContextKt.isParametrizedClass(CreateAndroidTestContext.kt:210)
        at ftl.run.platform.android.CreateAndroidTestContextKt.getParametrizedClasses(CreateAndroidTestContext.kt:200)
        at ftl.run.platform.android.CreateAndroidTestContextKt.getFlankTestMethods(CreateAndroidTestContext.kt:153)
        at ftl.run.platform.android.CreateAndroidTestContextKt.calculateShardsNormally(CreateAndroidTestContext.kt:86)
        at ftl.run.platform.android.CreateAndroidTestContextKt.calculateShards(CreateAndroidTestContext.kt:112)
        at ftl.run.platform.android.CreateAndroidTestContextKt.access$calculateShards(CreateAndroidTestContext.kt:1)
        at ftl.run.platform.android.CreateAndroidTestContextKt$setupShards$2$1$1.invokeSuspend(CreateAndroidTestContext.kt:49)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at ftl.domain.RunTestAndroidKt.invoke(RunTestAndroid.kt:62)
        at ftl.presentation.cli.firebase.test.android.AndroidRunCommand.run(AndroidRunCommand.kt:54)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at ftl.Main$main$1.invoke(Main.kt:12)
        at ftl.Main$main$1.invoke(Main.kt:10)
        at ftl.run.exception.ExceptionHandlerKt.withGlobalExceptionHandling(ExceptionHandler.kt:28)
        at ftl.run.exception.ExceptionHandlerKt.withGlobalExceptionHandling(ExceptionHandler.kt:17)
        at ftl.Main.main(Main.kt:10)
@kkoser
Copy link
Contributor

kkoser commented Aug 23, 2021

Hmm, a few preliminary questions:
-do you use any custom annotations in your tests?
-do you utilize test class inheritance?
-do you have multiple test dex files? How large is your project?

It sounds like its possible proguard is stripping out an annotation but isnt entirely getting it and there's still references in the dex somewhere? Not sure. Would you be comfortable sharing your proguard config?

If you're comfortable building the project yourself, would be interesting to see some more logs added so we can see exactly what class is being parsed when it fails, which would probably help narrow it down.

@juliocbcotta
Copy link
Author

juliocbcotta commented Sep 3, 2021

Sorry for the delay, I was on vacations.

Hmm, a few preliminary questions:
-do you use any custom annotations in your tests?
-do you utilize test class inheritance?
-do you have multiple test dex files? How large is your project?

It sounds like its possible proguard is stripping out an annotation but isnt entirely getting it and there's still references in the dex somewhere? Not sure. Would you be comfortable sharing your proguard config?

If you're comfortable building the project yourself, would be interesting to see some more logs added so we can see exactly what class is being parsed when it fails, which would probably help narrow it down.

I don't use any custom annotations, just Test, RunWith and Suite.SuiteClasses.
Yes, I do utilize test class inheritance.
Yes, The apk and test apk generate multiple dex files. Around 70 AndroidTests for 400k loc in the project.

I am able to run the UI tests from Android Studio (debug but with proguard enabled). Just when using flank/fladle I get that output. I just updated to the latest version of flank (21.09.0) and I can still reproduce this.

Attached you have the output of -printconfiguration proguard-config.txt in my proguard files.
proguard-config.txt

@juliocbcotta
Copy link
Author

@kkoser does the information I provided help ?

@juliocbcotta
Copy link
Author

I was able to fix it by updating r8 to the latest version available. Thanks for the help and sorry for the trouble.

buildscript {
    repositories {
        maven {
            url = uri("https://storage.googleapis.com/r8-releases/raw")
        }
    }

    dependencies {
        classpath("com.android.tools:r8:3.0.72")  // <-- R8 version 3.0.72
        classpath('com.google.guava:guava:30.1.1-jre')  // <-- THIS IS REQUIRED UNTIL R8 3.2.4-dev
    ...    
    }

@dmitry-ryadnenko-izettle
Copy link
Contributor

We have the same issue with Android Gradle Plugin 7.0.4. Should this be reopened?

@bootstraponline
Copy link

We have the same issue with Android Gradle Plugin 7.0.4. Should this be reopened?

I'd recommend opening a new issue, since it looks like you're still encountering the problem on the latest version of r8.

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

No branches or pull requests

4 participants