Nightly build for android project using gradle - android

I have an android project which I'm developing in windows environment.
Also a remote git repository exist which I push my project to it daily.
My requirement is to have a mechanism to automate daily(or nightly) builds.
I know that I can build my project in command line by aid of "gardlew.bat". This wrapper is special to my environment (windows) and I need to build the project on remote git repository which is on a linux machine.
How can i build my project on a linux machine using command line?

As part of your project's root files, you can find "gradlew.bat" that is meant to run on windows machines, and a "gradlew" file that is meant to run on a unix based system.
To build from unix command line, clone your entire project into the linux based machine and run the following command:
./gradlew assembleRelease
You need to make sure that your environment is set up correctly (JDK is installed and JAVA_HOME is configured correctly).
For detailed explanation, please refer to the Android Studio developers site for more information.

You can install Jenkins and configure a job for building (and testing, if you have some tests) your application. Configure this job to run periodically (via embedded cron).
Jenkins can
clone source code from the repo
run gradle with the task(s) specified
save *.apk (save artifacts in Jenkins terminology)
run tests
and many other useful things you may be interested in
Consult https://jenkins.io/index.html

Related

want to schedule a job in windows slave for android project by using gradle as build tool

In my Jenkins environment Linux as master and windows as slave. I want to build a job in windows slave machine for android project. I have installed android sdk and git and java and downloaded gradle in windows slave machine. How we can configure a build job and where we can provide that gradle path and android sdk path?
Use the Gradle Wrapper with your Gradle project, then you never need to install Gradle anywhere, as the Gradle wrapper bootstraps the Gradle distribution automatically.

Build (not develop) your android app .apk (gradle build) on server?

I'm trying to build(not develop) an android application on server. I've the whole native android code on the server, which I need to build according to some modification done on the server.
I've been looking all over the internet but couldn't find any detailed solution. All I got to know was I might need Jenkins or some CI tool (which I think is time consuming as I'll need to get them installed on server and then all the android dependencies).
Initial idea was to build the .apk file via some python script which contains all the gradle commands in it.
How can i do this?
Android apps can be built easily on a system that doesn't have any Android tools installed by applying the Android SDK Manager plugin for Gradle to your project.
When running ./gradlew assembleDebug (or whatever task), then Gradle will be installed and then all Android dependencies, including the SDK tools, build tools, platform versions and other dependencies will be installed automatically.
You can run this simply on the command line yourself, or automate to run after every commits to source control easily with Jenkins (it's easy to install on a wide range of operating systems).
You need to install Stand-alone SDK tools and suitable SDK packages to your server to build Android software.
When you have all installed and good, you can build APK with gradle , e.g.
(Linux and Mac)
./gradlew assemble

How do I update an Android project from a Jenkins job?

I am setting up Jenkins to clone my git project, update the project, then build using ant. If I perform an ls in the job after cloning the repo, I see my project.properties file present (containing target).
To update the project (and therefore generate the build.xml file) I issue the following command:
android update project -p ./
However, I get the following console output:
Error: The project either has no target set or the target is invalid.
Does anyone know how to update an android project from Jenkins and avoid this problem?
So you've eliminated the first part of the error (i.e. the project does have a target set), but not the second part.
The message "target is invalid" means that you don't have the target platform installed in the Android SDK that Jenkins is using.
e.g. if your target is android-17, then you need to install the Android 4.2 platform (for example via the command android update sdk -u -t android-17).
As an aside, you can automate both the relevant calls to android update -p and the installation of required target platforms using the Android Emulator Plugin for Jenkins.

How to debug android project from git using Jenkins frontend?

I have installed Jenkins on my ubuntu 11.04 system using command "apt-get install jenkins".
I am able to executes "ant debug" command from linux command line well and completed successfully But when i am trying to debug Android project from git hub using jenkins frontend by setting build target "Invoke ant" with properties "sdk.dir=/opt/android-sdk-linux-ics". It is giving following error Console Output :
########################################################################################
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/touchanimtn
Checkout:touchanimtn / /var/lib/jenkins/workspace/touchanimtn - hudson.remoting.LocalChannel#72cd429b
Using strategy: Default
Last Built Revision: Revision 3e4b580644fad8b059fb5c13925d3d86fa402187 (origin/HEAD, origin/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from https://github.com/ssamar/touchanimtn.git
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Commencing build of Revision 3e4b580644fad8b059fb5c13925d3d86fa402187 (origin/HEAD, origin/master)
Checking out Revision 3e4b580644fad8b059fb5c13925d3d86fa402187 (origin/HEAD, origin/master)
Warning : There are multiple branch changesets here
[touchanimtn] $ ant -Dsdk.dir=/opt/android-sdk-linux-ics clean debug
Buildfile: /var/lib/jenkins/workspace/touchanimtn/build.xml
BUILD FAILED
/var/lib/jenkins/workspace/touchanimtn/build.xml:83: Cannot find /opt/android-sdk-linux-ics/tools/ant/build.xml imported from /var/lib/jenkins/workspace/touchanimtn/build.xml
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
###################################################################################
I also tried by putting "android-sdk-linux-ics" into home folder but gave same error.
Please, Give me the correct solution for this error.
Either the root of your Android SDK isn't at /opt/android-sdk-linux-ics (i.e. the tools directory should be in there, with no intermediate directories), or the SDK does exist there, but the jenkins user doesn't have permission to access it.
This is a good question that more people will face when installing Jenkins on a linux system where the android SDK was installed before.
The problem is either that the path to the android SDK is not correct (1) or insufficient permissions for the jenkins user to access the android SDK installation path (2).
1) Path: Double check the path on your ant build step for the failing jenkins project. Go to the ant build step and click advanced. There it should have sdk.dir=SOME/PATH listed in the properties field. For multiple values make sure you expand the field and use a new line per value. Also don't include the -D to your argument since Jenkins will do that for each line.
2) Permissions: Double check the permissions on the android-sdk folder listed there. Use ls -l to get a list of current permissions and chmod to update the permissions if needed.
Notes:
It's always a good idea to switch to the jenkins user on your system and test the failing commands from the shell yourself.
sudo su jenkins
I had this kind of error also when I enabled security on my jenkins configuration. You can disable security without loosing settings by stopping the jenkins service, renaming the config file and restarting the service.
sudo service jenkins stop
sudo mv /var/lib/config.xml /var/lib/config.xml.backup
sudo service jenkins start
I didn't check in depth what user should get permissions in that case but I know reverting this change fixed the issue. Also I could still execute the ant scripts with the jenkins user as listed before.
This questions is very similar: Building android project from jenkins under linux - build fails, cannot find imported build.xml
Might help someone.
Wherever ANDROID_HOME/platforms pointing to
Reach in finder
bring get info
add Jenkins user and
give read access.
This solved my problem of build.xml not found error.

Compile Android project in Continuous Integration System Hudson?

I'm setting up a Continuous Integrations System with Hudson and it's just amazing.
I got a SVN repository and integrated a post-commit hook that notifies Hudson when someone commits to the repository. This part is working splendid.
The general idea is, that if the project fails, with unit-tests or anything else, it should tell the collaborator(i'm using a simple e-mail notifier atm). But if it successes I want it to compile the project and build either an unsigned or a signed .apk file.
What's the easiest or smartest way to do this?
I've read you can use a Shell Command to build the .apk but I can't seem to figure out how this works? Can anyone tell me how I can do this or should I go for another solution?
Thanks in advance
Finn Larsen
There is a guide on the Jenkins wiki about building Android apps with Hudson or Jenkins, including building and running a test app, obtaining code coverage and static analysis stats.
Essentially you can use the Ant support built-in to build your application.
If you want to run automated tests, you can also use the Android Emulator Plugin.
Since you're just starting out with Hudson, I would say now is a good time to upgrade to Jenkins. ;)
As far as I remeber hudson supports ant's builds. And android apps can be built using ant use this link for more info about building android apps with ant. Be aware that you'll have to install Android SDK on your build agent.
Android provides ant build script. So, you can make apk easily.
install android-sdk in hudson server
install ant in hudson server ( ant version should be > 1.8 )
in hudson, call cmd android update project -p <PATH to your project>
in hudson, call ant debug. debug target generates debug apk build

Categories

Resources