Install the Apk App and instrumentationApk for the Spoon Gradle Plugin

I would like to install .apk files that will be used to run my tests using SpoonGradlePlugin.

There are available properties that I can programmatically set from the gradle file:

https://github.com/stanfy/spoon-gradle-plugin/blob/master/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy

But my project has different tastes and names, and I would like to test them. With the current setup, I get:

* What went wrong: A problem was found with the configuration of task ':app:spoonDebugAndroidTest'. > File '/Users/F1sherKK/Dev/MyApp-Android/app/build/outputs/apk/app-debug.apk' specified for property 'applicationApk' does not exist. 

My build names:

 app-debug-androidTest-unaligned.apk MyApp-debugA-1.2.3-201.apk MyApp-debugB-1.2.3-201.apk MyApp-debugC-1.2.3-201.apk 

This is why I would like to configure my .apk somewhere in gradle code - or in the console. What I have found so far, there are fields available in the Spoon gradle plugin there:

https://github.com/stanfy/spoon-gradle-plugin/blob/master/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy

with names:

  /** Instrumentation APK. */ @InputFile File instrumentationApk /** Application APK. */ @InputFile File applicationApk 

But I cannot access those that are in gradle as properties in SpoonExtension.groovy.

Is there any way to configure these fields?

// EDIT - some attempts were added: This is my basic spoon configuration:

 spoon { debug = true baseOutputDir = file("$buildDir/spoon-log") if (project.hasProperty('spoonClassName')) { className = project.spoonClassName if (project.hasProperty('spoonMethodName')) { methodName = project.spoonMethodName } } } 

And tasks that extend it and overwrite instumentationArgs to install the package and run other tests.

 task spoonAllTests(type: GradleBuild, dependsOn: ['spoon']) { spoon { instrumentationArgs = ["package=com.myapp.sendmoney.instrumentation"] } } task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) { spoon { instrumentationArgs = ["package=com.myapp.instrumentation.flowtests"] } } 

And now I'm trying to edit the applicationApk or instrumentationApk file:

enter image description here

enter image description here

enter image description here

Edit2: I tried a new thing:

 task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) { spoon { inputs.property("applicationApk", "$buildDir/outputs/apk/ap12345p-debug.apk") inputs.property("instrumentationApk", "$buildDir/outputs/apk/ap125p-debug.apk") println inputs.getFiles() println inputs.getProperties() instrumentationArgs = ["package=com.azimo.sendmoney.instrumentation.flowtests"] } } 

And the terminal response:

 2015-10-26 20:24:12 [SR.runTests] Executing instrumentation suite on 0 device(s). 2015-10-26 20:24:12 [SR.runTests] Application: com.azimo.sendmoney.debug1 from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug.apk 2015-10-26 20:24:12 [SR.runTests] Instrumentation: com.azimo.sendmoney.debug1.test from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug-androidTest-unaligned.apk :app:spoon :app:spoonFlowTests file collection {instrumentationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap125p-debug.apk, applicationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap12345p-debug.apk} :Azimo-Android:app:help Welcome to Gradle 2.5. To run a build, run gradlew <task> ... To see a list of available tasks, run gradlew tasks To see a list of command-line options, run gradlew --help To see more detail about a task, run gradlew help --task <task> BUILD SUCCESSFUL Total time: 13.289 secs 
+5
source share
4 answers

See my answer to your other question , explaining what is not the way you set up your tasks.

0
source

You can apply the Spoon plugin after changing the apk name as follows:

 applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent, output.outputFile.name.replace(".apk", "-${variant.versionName}.apk")) } } afterEvaluate { apply plugin: 'spoon' spoon { debug = true; } } 

Source: https://github.com/stanfy/spoon-gradle-plugin/issues/70

+4
source

We need to consider the annotation of the parameters:

  /** Instrumentation APK. */ @InputFile File instrumentationApk /** Application APK. */ @InputFile File applicationApk 

Since they are marked as @InputFile , we should be able to create a custom task that depends on Spoon, which passes inputs using the input.files property .

Sample example (untested):

 task customSpoon(type: Exec, dependsOn: spoon) { inputs.files ["path/instrumentation.apk", "path/debuggable.apk"] } 

UPDATE

Alternatively, simply create a custom task that simulates a parameterized command line call to a basic Spoon task, for example the following

 task runSpoonTask(type: Exec) { commandLine './gradlew', 'spoon', '$buildDir/outputs/apk/ap12345p-debug.apk', '$buildDir/outputs/apk/ap125p-debug.apk' } 
0
source

I had the same problem:

... the specified for the 'applicationApk' property does not exist

We used this to rename from "app-debug.apk" to "currentProject-debug.apk":

 applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent, output.outputFile.name.replace("app", "${project.hdmiAppName}")) } } 

But it seems that this works much better with Spoon:

 defaultConfig { applicationId packageName ... setProperty("archivesBaseName", "${project.hdmiAppName}") } 

This will rename the "app" -Part APK-Name at any time convenient for you. In our case, we have "${project.hdmiAppName}" specified in the properties file. But I think it could also be "MyApp-${versionName}" .

0
source

Source: https://habr.com/ru/post/1234290/


All Articles