GradleHelpers


Source link: https://github.com/brunodles/GradleHelpers

Gradle plugin

This repo is intended to have all my gradle plugins, tasks and any other gradle files.

Here I'll add custom tasks and build examples of how to use then.

The idea was simple, find and provide a way to reuse those tasks without messing up my build.gradle.

This could also be used as a helper to show how to use some of gradle capabilities.

My Gradle Plugins

Here are the links to my other gradle plugins/tasks.

What is in this Repo?

Cexec Task - Custom Execute

This is a simple executor, sometimes the default exec task does not work as expected. I wrote this simple task just to trigger some terminal commands from a gradle task.

It's on another repo to simplify the releases, the link is here. There are few examples about how to use it.

JitPack

This is just a simple gradle file that can be used to keep some jitpack tasks.

The idea around it is to just import this file, instead of copy the tasks.

apply from: 'jitPack.gradle' apply from: rootProject.file('jitPack.gradle') apply from: uri('https://raw.githubusercontent.com/brunodles/GradleHelpers/master/jitpack/jitPack.gradle')

In the code above we have 3 ways to import a gradle file into another.

  1. Apply from relative path.
  2. Apply from root project path.
  3. Apply from a uri, won't work without internet.

I prefer to copy the script into the gradle dir, you will be able to see some projects using this way too.

apply from: rootProject.file('gradle/jitPack.gradle')

Ip Getter

This is a script that I found on internet, with it the app is able to change the API address depending on build type.

Setup

To use it you just need to apply the script. Take a look on what we did for [jitpack](## JitPack).

apply from: 'ip.gradle' apply from: rootProject.file('ip.gradle') apply from: uri('https://raw.githubusercontent.com/brunodles/GradleHelpers/master/ipgetter/ip.gradle')

How to use

After the apply you need to use the getApiUrl method. To do so, you need to create a buildConfigField inside your app level gradle file project/app/build.gradle.

apply from: rootProject.file('gradle/ip.gradle') ... android {

...
defaultConfig {

  ...
  buildConfigField "String", "API_URL", '"http://localhost"'

}

buildTypes {

  ...
  debug {

 ...

 buildConfigField "String", "API_URL", "\"${
getApiUrl()
}
\""
  
}

}
 
}

More Info

I've added another way to setup this, take a look

Another Way to use and more Examples

I also release this as a gradle plugin, with makes it easy to use.

preBuildSetup - Dynamic Project Properties

Change project properties before build the app.
This sample is intended to be used as a template for the other tasks. With it you will be able to replace some project properties dynamically.

How to use

Just create a new task

task preBuildSetup() {

 description "Setup project with dynamic properties before build the app"
 group 'build'
 doLast {

  android.applicationVariants.all {
 variant ->

// if you are planning to have multiple dynamic properties changed here, add a verification for the parameter.

// if (project.hasProperty("<parameter name>"))

variant.mergedFlavor.<property> = <parameter name>

  
}

 
}

 // if you are planning to have multiple dynamic properties remove the `project.hasProperty("versionName") &&` bellow. Just check the android.
 onlyIf {
 project.hasProperty("versionName") && it.hasProperty("android") 
}
 
}
 project.tasks.getByName('preBuild').dependsOn('preBuildSetup')

On the terminal you can type

./gradlew assembleRelease -PversionName=42

Sample

I use a similar task to change my version name based on my current pr, with this I can build a pr-release version.

task changeVersionName() {

 description "Change the version name before build the app"
 group 'build'
 doLast {

  android.applicationVariants.all {
 variant ->

variant.mergedFlavor.versionName = versionName

println "Changed the versionName to ${
versionName
}
"

  
}

 
}

 onlyIf {
 project.hasProperty("versionName") && it.hasProperty("android") 
}
 
}
 project.tasks.getByName('preBuild').dependsOn('changeVersionName')

Git

This is a simple file to integrate some of git functions in your gradle file. I wrote it to simplify some of the tasks I have to do on the job, on my own projects and even on the OpenSource projects.

Setup

apply from: 'git.gradle' apply from: rootProject.file('git.gradle') apply from: uri('https://raw.githubusercontent.com/brunodles/GradleHelpers/master/git/git.gradle')

How to use

Right now, I just wrote two tasks.

Last tag in current branch

This method can get the last tag on the current branch. The idea is simple, I can use the tag anywhere in my gradle file, but I wrote it to make my life easier to make my OS releases, since JitPack uses only my repo tag, I made the command gradle install do the same.

group 'com.github.brunodles' version getLastTagInCurrentBranch()

Current Branch Name

This method can get the current branch name. Can be used anywhere in the gradle file. I wrote it to be used in together with Slackupload, but you can use to add some more informations to your build info, for crash and analytics tools.

Contributing

You can contribute but showing your custom tasks, or submitting a new task. Issues are welcome, create one and we will discourse about it. If you saw any error, please reports, it will be a great help.

Licence

You can use any code you found here, some of then I found on the internet too.

I'm using the MIT Licence, take a look on Licence.

If you're using this plugin, please give me some credits too.

Sources

Gradle

Ip Inject

This one have many sources, I don't remember where I found it at first, it was on 2014. Now we have many articles about it, so I'll link then.

VersionName

Thanks to Barry, he wrote a sample about how to write a plugin to change the version name.

JitPack

Read Inputs on Gradle tasks

Gradle running groovy scripts

Links

Resources

Easy font usage in your Android XML layouts

  • Based on Data Binding
  • Written in Kotlin
  • Automatic initialization
  • Automatic font caching
  • Homogeneous android:font usage
  • Tiny size: 14 KB
  • Minimum Android SDK: 7
  • Available through jCenter

Plugin for AndroidAnnotations allowing to use it together with PermissionsDispatcher. All you have to do is to include it in your dependencies.

A framework for building Mobile cross-platform UI.

A version info widget for Android with material style.

FogView is a android library that can show fog on any layout and the fog removes when user rubs it.

A custom Android TextView to display amounts of money in different formats.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes