Spoon with Espresso, Eclipse & Jenkins - android

call java -jar spoon-runner-1.1.1-jar-with-dependencies.jar
-- apk D:\Workspace\gitrepo\ProjectX\bin\ProjectX.apk
-- test-apk D:\Workspace\gitrepo\ProjectXTest\bin\TestX.apk
I created a folder in my workspace & added spoon runner jar in that folder. Also, I placed spoon client jar in my test project's libs folder. When I'm executing the batch file, nothing happens.
Also, looking for a way to integrate the test report[well, if I can run it] in my Jenkins automated post build email.
If anybody can give a step by step answer it will be really helpful.
Thanks.

If you can, I really recommend moving your project to Android Studio and using the Spoon Gradle plugin. Running spoon with a Gradle setup is much easier.

Try to run directly from command line(I think you have space between "--" and the parameters, try --apk, --apk-test, like the following):
call java -jar spoon-runner-1.1.1-jar-with-dependencies.jar --apk D:\Workspace\gitrepo\ProjectX\bin\ProjectX.apk --test-apk D:\Workspace\gitrepo\ProjectXTest\bin\TestX.apk

Related

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

My build.gradle for an Android app has become quite lengthy. Chanced upon this plugin called gradle-lint-plugin and configured it properly. In its documentation it says
Run ./gradlew fixGradleLint to automatically fix your build scripts
but upon running that I get Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain.
Does this have anything to do with the Android Studio using its own Gradle plugin? I do not have Gradle installed systemwide.
Edit: I do not wish to install Gradle systemwide - is there any way to do this within Android Studio only?
Sounds like the wrapper is not setup correctly. Likely missing the wrapper jar.
$ ls gradle/wrapper
gradle-wrapper.jar gradle-wrapper.properties
When you look in gradle/wrapper do you see gradle-wrapper.jar?
if you install gradle you can generate the jar with this command:
$ gradle wrapper
I was having this error and I solved it correcting the path which had special caracters.
Ex: .../T&G/appmobile
to ../TG/appmobile
This sometimes happens if you have "&" or "/" kind of special characters in your folder or in the parent folder. Rename those folders and the error is simply gone.

Android Studio: Migrate complex build.xml to build.gradle

I have migrated my project from eclipse to android studio successfully and a default build.gradle file has been generated. The project builds correctly and I can deploy to debug etc.
The real problem though is building release APK files (from the command line) for which I used to have a custom ant-build (called via command line, not out of eclipse).
My custom build.xml imported the standard sdk build.xml file from the SDK folder via:
<import file="${sdk.dir}/tools/ant/build.xml" />
So all I had to do in my build.xml was to override targets or hook into them via "depends".
An example for an override:
<target name="-set-release-mode" depends="-set-mode-check">
<!--Here I rename my output apk files to something like: myapp-versionFromAndroidManifest.apk -->
</target
And an example for adding dependency:
<target name="-pre-build" depends="clean">
<!-- my custom code where I copy resource files, process command line arguments
use xpath to extract things like the version from the AndroidManifest.xml and
write them into custom xml files etc... -->
</target
So overall the whole affair was really simple using ant. But now when it comes to migrating to gradle I am at a total loss, how to accomplish the same that I previously did in ant, specifically:
For the build.xml there is a default build.xml that I imported in my ant build - does a standard build.gradle file exist somewhere so I can check out the defined tasks?
Is it possible to override gradle tasks and if yes: how?
I am pretty certain the depends="..." from ant can be mimicked in gradle but I have no idea how and that would also require an answer to question 1.
I googled a bunch of tutorials, also migration tutorials like (which unfortunately didn't address my issues):
http://keepsafe-engineering.tumblr.com/post/87818767721/migrating-android-app-from-ant-to-gradle
http://ryanharter.com/blog/2013/07/17/migrating-android-projects-to-gradle/
I also read this chapter from the gradle docs which didn't really help at all, because it does not answer question 1 or 2 or 3 for that matter:
http://www.gradle.org/docs/current/userguide/ant.html
The following gave some interesting pointers though:
http://toastdroid.com/2014/03/28/customizing-your-build-with-gradle/
I also tried simply copying the default build.xml from the sdk folder into my own build.xml and then simply importing that ant build file in gradle and executing the ant task that kicks of the build:
<target name="release"
depends="-set-release-mode, -release-obfuscation-check, -package, -post-package, -release-prompt-for-password, -release-nosign, -release-sign, -post-build"
description="Builds the application in release mode.">
</target>
but I started running into problems that suggested this is not an option anymore, since the default build.xml started throwing errors, that seemed related to the SDK version. And I had to mess around a lot with the original sdk build.xml because of the new android studio project structure, so files were not where they were expected etc...
First, I would suggest you import the legacy project to android
studio. It will create the appropriate build.gradle script for you.
And then, you can list the task list by executing gradlew tasks at
the root of your project.
To depend on some tasks, you can use command such as init.dependsOn anotherTask.
Just for the record: I dumped the idea of using my previous ant-build and completely migrated to gradle. Most of the stuff I needed to do could be achieved just by the directory structure. You can find details on how I did that in my other question:
Android Studio: Gradle Product Flavors: Define custom properties
Now the second part was to call my java code that did some stuff I really did not want to migrate to groovy/gradle. Thus I figured out how to execute my java class (albeit I actually had to make a jar file out of it) from the gradle script:
Android Studio Gradle: Execute static Java Method (Migration from ANT to Gradle)
If anyone has questions, I'll be happy to try my best and answer them.

Ant Build Android Project With Dependencies

I'm trying to build an app (let's call it android-app) with a dependency on an SDK (let's call it sdk) via Ant. Eclipse is not installed on this computer (for reasoning, it's a CI box with Jenkins).
Both projects are in two completely separate directories side by side. android-app is in the directory ~/.jenkins/jobs/android-app/workspace and sdk is in the directory ~/.jenkins/jobs/sdk/workspace.
Let's assume both projects are "vanilla" and have not been built with Ant before. I cd to the ../android-app/workspace directory and run android update project -p . --library ~/.jenkins/jobs/sdk/workspace which passes. I then cd to the ../sdk/workspace directory and run android update project -p . which also passes.
At this point I cd back to the ../android-app/workspace directory and run ant clean build. It fails with the error:
BUILD FAILED
/path/to/ant/build.xml:440:
/path/to/sdk/workspace resolve to a path with no project.properties file for
project /path/to/android-app/workspace
... where /path/to is the full path to the directories. I simplified it here.
If I cd to the sdk workspace and open project.properties, I receive the following:
# ProGuard
proguard.config=proguard.cfg
# Project target.
target=android-10
android.library=true
It does exist. So do all of these files:
So, why is this failing? What am I doing wrong? I tried to provide as many details as possible. Please let me know if I can provide anything additional.
Well, I encounter this problem too.
I use strace to find out what the hell is going on and found that the path you specified in project.properties will be appended with your current folder path as its prefix.
For example,
/home/myfolder/project > ant debug
And the library you specified in project.properties is /path/to/library
Then, the path will become
/home/myfolder/project/path/to/library
Just to fill in the answer gap here, my Java version was completely off. I'm super embarrassed.

Emma does not generate coverage.ec

I setup Emma and it used to work for me. Then we had source code changes and now it doesn't generate coverage.ec at all. It does generate coverage.em.
Near the end of testing, it has error messages:
[exec] INSTRUMENTATION_CODE: 0
[echo] Downloading coverage file into project directory...
[exec] remote object '/sdcard/coverage.ec' does not exist
BUILD FAILED
/var/lib/jenkins/android-sdk-linux_x86/tools/ant/build.xml:1056: exec returned: 1.
Line 1056 of build.xml is
"{adb}" failonerror="true".
I see that I do have coverage.em on the desktop, which means my code are instrumented.
the command I use under the \test is
ant emma debug install test
This worked for me before. Running code coverage always crashes for me, usually near the end of the unit test, but it'd always get me some coverage. Now it crashes out and doesn't produce coverage.em.
I also tried to access /sdcard/ and it's perfectly accessible and writable.
This has blocked me for days, any input would be much appreciated. I am also new to all this Android, Ant and Emma, so thanks!!
Update:
I just cleaned up the environment and ran the command again.Now coverage.em is no longer generated either. Which tells me the source code are not instrumented. But the command I used above should instrument project, its test project, install and start test. I didn't change emma def in build.xml except to change the coverage.ec location to /sdcard/coverage.ec. This is because by default it goes to /data/data, and I don't have permission to access data/data on this phone
I am using r15 of Android SDK, and the default build.xml. I only changed the path to coverage.ec to /sdcard/coverage.ec. To run instrumentation
Go to main_project
$andriod update project -p .
Go to main_prject\test
$android update project -m ../ -p .
To start code code
$ant emma debug install test
It generated main_project-instrumented.apk and test_project-debug.apk. Both are installed and I can see it executes testing.
You have to make a test project with the android command line tools first.
Create Project & Test Project
Assuming your project is stored in D:\AndroidProject and your programming against android API level 8. First you use this command to create the project:
android update project --path ./ --name blabla~ --target android-8 --subprojects
Then create an folder for the test project and navigate into that folder:
mkdir Android_test
cd Android_test
Then create the android test project with the below command
android create test-project --main ../AndroidProject --path ./
Ant building with emma coverage report (with root)
Execute this command (from jenkins select and build step) to get a build done with emma reporting:
ant emma debug install test
Caution : For this to work you have to connect rooted device or emulator, then execute ant command!
Change Build xml file (so no root is required)
If you don't want to root your device an alternative solution is to alter the location of these coverage reports. For this you should modify the build.xml file.
(you should googling about that for more information, briefly explained here)
Open the build.xml -> find the location where the coverage.ec file is stored. In most cases this will be stored in /data/data/com.example.Android/coverage.ec
The problem here is that the /data/data/~~~ path is protected (hence the required root).
anyway~ you can get a coverage.html file in your test project folder/bin. The next steps explain how to change this to save this file on the /sdcardinstead!
You can open your build.xml file and at the last line ~ you can find the command import ~~~ build.xml which means that your build.xml file will import anoother build.xml file.
The other build.xml file is part of the android SDK and is located at ${Android-sdk}/tools/ant/build.xml.
Required changes for build.xml file
We can't change this file (without getting into trouble) so instead copy the complete file to an alternative location or directly into your projects build.xml file.
Don't forget to adapt or change the import statement in your build.xml file whatever you choose to do.
This is what you need to change in that new build.xml file:
Erase the import= ~~build.xml
Erase the first line which is xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
and last line /project
update address to /sdcard/coverage.ec
Then, you can get coverage.ec file~
I ran into this issue after updating my SDK to r16: Emma code coverage not working in r15 of tools
and this fixed it for me:
ant all clean emma debug install test
But I am unsure if you have the same problem.
I don't have permission to access data/data on this phone
Is it a non-rooted device? Note that the build says:
WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
Maybe you can't work around this limitation by just changing the location of the coverage file. Does it work on a virtual device?

Android ant build: how to run android upload and not update build.xml, proguard.cfg

I am running the standard ant script build.xml which gets created when you run the android create project command. In order to verify my local.properties is set correctly, I added a task at the beginning of the build.xml script to run the command:
android update project -p .
I now get the following message each time I run the ant script, which clobbers my build.xml file and creates a proguard.cfg file!
File build.xml is too old and needs to be updated
So, I moved the ant script to a different file that won't get clobbered.
Is there a way to run the command android update project -p . that doesn't clobber build.xml and create proguard.cfg?
I think this is a bug. I have registered a new bug with Google here:
http://code.google.com/p/android/issues/detail?id=17825
If anyone else thinks it's a bug, then please star it and perhaps contribute your thoughts.
Workaround for this. Add the following code in build.xml.
<!-- The following will prevent for 'android' tool to overwrite this file.
(until sdk r12)
classname="com.android.ant.SetupTask"
(since sdk r13 FIXME)
version-tag:custom
-->
With the piece of comment, 'android update project' will not complaint or overwrite the build.xml.
As of now, there might be chance for changes in r13.
sdk r13 not yet released
it's based on aosp/master branch
updateProject() in package com.android.sdklib.internal.project.ProjectCreator determine to update the build.xml or not.
(The code from sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java)
The build.xml generated by android has the following comment:
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
so, it looks like Atham is right.

Categories

Resources