Showing posts with label Gradle. Show all posts
Showing posts with label Gradle. Show all posts

Making symbolic link named ".m2" to Gradle JAR repo

After many years of using Maven, I am used to that my JARs are in ~/.m2/ directory, so I created myself a link as follows:


$ ln -s ~/.gradle/caches/modules-2/files-2.1 ~/.m2 

$ ls -alt ~/.m2/
total 0
drwxr-xr-x  65 ukilucas  staff  2210 Apr 28 23:18 .
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 23:18 junit
drwxr-xr-x   4 ukilucas  staff   136 Apr 28 23:18 org.hamcrest
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 com.android.tools.external.lombok
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 org.abego.treelayout

drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 com.intellij
..


As an Amazon Associate I earn from qualifying purchases.

Making symbolic link named ".m2" to Gradle JAR repo

After many years of using Maven, I am used to that my JARs are in ~/.m2/ directory, so I created myself a link as follows:


$ ln -s ~/.gradle/caches/modules-2/files-2.1 ~/.m2 

$ ls -alt ~/.m2/
total 0
drwxr-xr-x  65 ukilucas  staff  2210 Apr 28 23:18 .
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 23:18 junit
drwxr-xr-x   4 ukilucas  staff   136 Apr 28 23:18 org.hamcrest
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 com.android.tools.external.lombok
drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 org.abego.treelayout

drwxr-xr-x   3 ukilucas  staff   102 Apr 28 14:15 com.intellij
..


As an Amazon Associate I earn from qualifying purchases.

Gradle DSL method not found: 'runProguard'

The error appears when running Android Gradle:

Gradle DSL method not found: 'runProguard'

to fix it open app/build.gradle and fix this part as such:

    buildTypes {
        release {
            // runProguard false // not supported            

             minifyEnabled false            

             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }



As an Amazon Associate I earn from qualifying purchases.

Gradle DSL method not found: 'runProguard'

The error appears when running Android Gradle:

Gradle DSL method not found: 'runProguard'

to fix it open app/build.gradle and fix this part as such:

    buildTypes {
        release {
            // runProguard false // not supported            

             minifyEnabled false            

             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }



As an Amazon Associate I earn from qualifying purchases.

9a. Gradle upgrade

In this tutorial we will overview basics of Gradle build system.

Step 1: verify what Gradle version you have

$ gradle -version

------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------

Build time:   2016-04-25 04:10:10 UTC
Build number: none
Revision:     3b427b1481e46232107303c90be7b05079b05b1c

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_77 (Oracle Corporation 25.77-b03)
OS:           Mac OS X 10.11.4 x86_64



Step 2: update to the newest 

if you are missing entirely (on Mac using brew):

install brew on Mac:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and now install gradle on Mac

brew install gradle

If you are updating (on Mac using brew):

brew update && brew upgrade gradle
...
==> Downloading https://downloads.gradle.org/distributions/gradle-2.1-bin.zip

######################################################################## 100.0%



$ gradle -version
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time:   2014-09-08 10:40:39 UTC
Build number: none
Revision:     e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_20-ea (Oracle Corporation 25.20-b05)
OS:           Mac OS X 10.9.4 x86_64

$ which 

gradle/usr/local/bin/gradle



If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:
Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

9a. Gradle upgrade

In this tutorial we will overview basics of Gradle build system.

Step 1: verify what Gradle version you have

$ gradle -version

------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------

Build time:   2016-04-25 04:10:10 UTC
Build number: none
Revision:     3b427b1481e46232107303c90be7b05079b05b1c

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_77 (Oracle Corporation 25.77-b03)
OS:           Mac OS X 10.11.4 x86_64



Step 2: update to the newest 

if you are missing entirely (on Mac using brew):

install brew on Mac:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and now install gradle on Mac

brew install gradle

If you are updating (on Mac using brew):

brew update && brew upgrade gradle
...
==> Downloading https://downloads.gradle.org/distributions/gradle-2.1-bin.zip

######################################################################## 100.0%



$ gradle -version
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time:   2014-09-08 10:40:39 UTC
Build number: none
Revision:     e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_20-ea (Oracle Corporation 25.20-b05)
OS:           Mac OS X 10.9.4 x86_64

$ which 

gradle/usr/local/bin/gradle



If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:
Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

Gradle: Working with multi app projects in Android Studio

In this tutorial I wanted to share how is my project organized to work with multiple apps and libraries.




I have the following settings.gradle in the root of my Project:

include ':app'
include ':appBookShelf'
include ':appNFC'
include ':appUnitConverter'
include ':appUserPreferences'
include ':libraries:ListViewSwipeActivity'



Please note that I perpend my app names with "app.." to keep them organized, I also have a folder "libraries" where I keep the code of my submodules.

Here is my folder structure:


CIT299 $ t
.
├── CIT299.iml
├── app
│   ├── app.iml
│   ├── build
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src
├── appBookShelf
│   ├── build
│   ├── build.gradle
│   └── src
├── appNFC
│   ├── build
│   ├── build.gradle
│   └── src
├── appUnitConverter
│   ├── appUnitConverter.iml
│   ├── build
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src
├── appUserPreferences
│   ├── build.gradle
│   └── src
├── build.gradle
├── gradle
│   └── wrapper
├── gradle.properties
├── gradlew
├── gradlew.bat
├── libraries
│   └── ListViewSwipeActivity
├── local.properties
└── settings.gradle



As an Amazon Associate I earn from qualifying purchases.

Gradle: Working with multi app projects in Android Studio

In this tutorial I wanted to share how is my project organized to work with multiple apps and libraries.



As an Amazon Associate I earn from qualifying purchases.

9b. Gradle: AndroidStudio with submodules (library projects)

In this tutorial we will overview integration basics of Android Studio and Gradle build tools.



As an Amazon Associate I earn from qualifying purchases.

9b. Gradle: AndroidStudio with submodules (library projects)

In this tutorial we will overview integration basics of Android Studio and Gradle build tools.



Step 1: Verify local.properties file

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/Users/uki/Documents/Dropbox/Android/android-sdk-macosx


As noted, this is for us to only verify that we have the right Android tools directory specified.

I also have $ANDROID_HOME  in my ~/.profile which serves the same purpose

# ANDROID - updated: Oct 17, 2014
export ANDROID_HOME=~/Documents/Dropbox/Android/android-sdk-macosx
export PATH=${PATH}:${ANDROID_HOME}/build-tools/21.0.0
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_HOME}/tools

Remember to update build-tools to latest stable version, in my case Android Lollipop 5.0. API 21

If you are developing code with multiple people, verify that .gitignore file contains files that are specific only to you.

local.properties

Step 2: Gradle Project structure with library projects







Step 3: Gradle Wrapper "gradlew" permission to execute


I had to add execute (+x) permissions to my gradlew script

$ ./gradlew
-bash: ./gradlew: Permission denied
$ chmod +x gradlew


Run ./gradlew (.bat)

$ ./gradlew
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:help
Welcome to Gradle 1.10.
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

If you inspect gradle/wrapper/gradle-wrapper.properties you will notice it uses older Gradle jar:


$ more gradle/wrapper/gradle-wrapper.properties#Fri Oct 17 10:58:51 CDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip




However updating it to a newer one did not produce correct results, so I left it at original 1.10.

Step: Preventing duplicate dependencies

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;

Make sure that if your Library project has:

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
...

then you main App should not have the different version of the same jar.

Also do:

Build > Clean Project

Step: before writing of  a new build script always update Android SDK



Step: Writing example app build.gradle

While writing Gradle script use Android Studio tips:



The sections listed below are in the same order as in my project/app/build.grade file:

Step: plugin Android or Java?


apply plugin: 'com.android.application'



Step: buildscript{}



// build script is not necessary unless you want to provide non-standard configuration
buildscript {
repositories {
//mavenCentral()
// even if not necessary, I am giving example of other repo in case failure of mavenCentral
//jcenter()
}
dependencies {
// This is Android plugin for Gradle, not actual Gradle 2.1
// classpath 'com.android.tools.build:gradle:0.12.+'
}
}

Step: dependencies{}


dependencies {
    /**
     *  Include all jars from the lib directory.
     */
    compile fileTree(dir: 'libs', include: ['*.jar'])
    /**
     * You must install or update the Support Repository through the SDK Manager to use this dependency.
     * v4 is needed for Theme.AppCompat.Light.DarkActionBar
     **/
    compile 'com.android.support:support-v4:21.0.0'
    /**
     * Even if NOT recommended I use 19.+ notation, also I am not using 21.+ because of errors:
     * No resource found that matches the given name 'android:TextAppearance.Material'.
     * even if my SDK Manager is up to date with API 21.
     * since support-v7 is included in the libraries project it is not needed here.
     */
    // compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:appcompat-v7:19.+'
    /**
     * The main app depends on LIBRARY ListViewSwipeActivity
     */
    compile project(':libraries:ListViewSwipeActivity')
}

Step: repositories{}



/**
 * needed only if you have to specify non-standard configuration
 **/
repositories {
    mavenCentral()
    /**
     * even if not necessary, I am giving example of other repo in case failure of mavenCentral
     */
    //jcenter()
}


android{}

android {
    /**
     * compileSdkVersion is the same as the target property in the project.properties
     */
    compileSdkVersion 21 // Lollipop 5.0
    /**
     * Check Android SDK Manager for the NEWEST tools version:
     */
    buildToolsVersion '21.0.2' // Lollipop 5.0
    defaultConfig {
        versionCode 1
        versionName "1.0"
        /**
         * minSdkVersion should be set to 7 if you depend on support-v7.
         */
        minSdkVersion 7
        targetSdkVersion 21  // Lollipop 5.0
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    /**
     * I am using default Gradle locations,
     * but if you use Ant based projects you may have to adjust
     */
    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            aidl.srcDirs = ['src/main/aidl']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
            //renderscript.srcDirs = ['src']
            //resources.srcDirs = ['src']
        }
        /**
         * androidTest.setRoot moves the whole sourceSet (and its sub folders) to a new folder.
         * This moves src/androidTest
         */
        androidTest.setRoot('tests')
    }
}




As an Amazon Associate I earn from qualifying purchases.

Gradle Integration for Eclipse

Open URL:
https://marketplace.eclipse.org/content/gradle-integration-eclipse

Click "Install"and drag it to your open Eclipse.

this easy.


As an Amazon Associate I earn from qualifying purchases.

Gradle Integration for Eclipse

Open URL:
https://marketplace.eclipse.org/content/gradle-integration-eclipse

Click "Install"and drag it to your open Eclipse.

this easy.


As an Amazon Associate I earn from qualifying purchases.

apt quotation..