Thursday, March 23, 2017

Fun with Gradle

Hi All,

Greetings for the day!!!

Have been wondering from many days as to why should I use Gradle if same features are provided by xcodebuild also

  • A command line tool provided by Apple that creates builds/packages.
  • It can take input target, scheme, ipa name, signing information etc in the arguments.
  • Supports multiple tasks and environments.
  • Can be integrated with Jenkins too.


Then why Gradle??
  • Build Management along with Dependency Management. Xcodebuild can only do build management and for dependency management it needs Cocoapods.
  • If you are working on multiple platforms like iOS and Android then Gradle is the common choice for both.

Now how to Use Gradle with Xcode

  • In terminal java -version should be 7 
  • if not type $ brew cask install java  or $ brew cask install Caskroom/versions/java7
  • Download gradle via homebrew $ brew install gradle
  • Type $ gradle -v to check its version

2) Create build.gradle file for your project.
3) Navigate to project directory in terminal.
4) $ gradle build
5) Project builds
ta da....


Sample build.gradle file

plugins {
  id "org.openbakery.xcode-plugin" version "0.14.5"
}

xcodebuild {
     target = 'Hello-Gradle'

/* If need to differentiate between iOS and android */
     type = 'IOS'             

/* Set ipa file name*/
     ipaFileName = ipaName 

 /* if u wish to create archive its necessary to set simulator as FALSE coz for archive we need DEVICE*/
     simulator = false        
}


To execute above file code you can also use:

$ gradle xcodebuild 

No comments:

Post a Comment