How to fix Gradle -P arguments not working in PowerShell

Executing this command in PowerShell:

./gradlew createGplayDebugCoverageReport -Pcoverage=true -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerContentProviderClientIT

gave me the weird error

A problem occurred evaluating project ':app'.
> No such property: applicationVariants for class: java.lang.String

Turns out, PowerShell can interpret the -P as a parameter for the script or command, not as an argument to Gradle, which leads to parsing problems.

Solution: Use –% to Stop PowerShell from Parsing Arguments

./gradlew --% createGplayDebugCoverageReport -Pcoverage=true -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerContentProviderClientIT

Bonus: I used Github Copilot to have this explained to me and it actually hallucinated a reference.

It gave a link to https://stackoverflow.com/questions/36540081/gradle-p-arguments-not-working-in-powershell which actually resolves to an unrelated article https://stackoverflow.com/questions/36540015/how-to-reduce-apk-apk-size-in-android-studio/36540081#36540081. So I figured, let’s make this article a reality!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.