Using Jenkins to build an android gradle project fails

I’m trying to setup Jenkins on a computer running OSX and I’m running into a problem.

When I’m trying to build the project with my default user account everything works fine, but as soon as im trying to build via Jenkins the build fails with the following output:

  • How to implement a confirmation (yes/no) DialogPreference?
  • How to collapse the AppBarLayout animated without pushing the content, similar to WhatsApp Android?
  • Prevent multiple copies of an Android service
  • Android Build fail - java.lang.IllegalArgumentException: already added: Lcom/google/api/client/escape/CharEscapers;
  • Android: How do I attach a temporary, generated image to an email?
  • Using Pull to Refresh gridview in viewpager in Activity inside ActivityGroup causes ClassCastException
  • FAILURE: Build failed with an exception.
    
    * What went wrong:
    A problem occurred configuring project ':Project'.
    > Failed to notify project evaluation listener.
        > A problem occurred configuring project ':libraries:actionbarsherlock'.
            > Failed to notify project evaluation listener.
                > Could not resolve all dependencies for configuration ':libraries:actionbarsherlock:compile'.
                    > Could not find com.android.support:support-v4:13.0.0.
                      Required by:
                          workspace.libraries:actionbarsherlock:unspecified
    

    My build.gradle for the project ‘libraries:actionbarsherlock’ looks like this:

    buildscript {
        repositories {
            maven { url 'http://repo1.maven.org/maven2' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
        }
    }
    apply plugin: 'android-library'
    
    dependencies {
        compile 'com.android.support:support-v4:13.0.0'
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "17.0.0"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 16
        }
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
            }
        }
    }
    

    As far as I know the dependency to com.android.support:support-v4:13.0.0 should be satisfied through the local maven repository installed via the Android SDK Manager. As I said this is working when building on my user account, but it seems to fail when trying to build with Jenkins.

    UPDATE

    I was able to resolve this issue by checking the user permissions on my android-sdk folder. Problem seemed to be that while the jenkins user had read&write permissions on the android sdk root folder it was lacking the permissions to access stuff installed through the android sdk manager.

    Related posts:

    How to detect if android device is paired with android wear watch
    Turn off screen on Android
    Android: strange error in Manifest
    Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    Android ActionBar is not displaying icons
    Button highlight behavior changed on Froyo?
  • How to store class object in android sharedPreference?
  • Android - LinearLayout Horizontal with wrapping children
  • PictureListener and onNewPicture() are deprecated - Alternatives?
  • Make a wizard like application in Android
  • Android ADB access to application databases without root
  • Don't collapse Toolbar when RecyclerView fits the screen
  • 3 Solutions collect form web for “Using Jenkins to build an android gradle project fails”

    I was able to solve this issue just now for myself.

    Steps:

    1. Create a file in the root directory of your project called “local.properties”
    2. Put only the following in the file:
      sdk.dir=/home/patience/android-studio/sdk

    Then Rebuild and it should work. This was on Fedora Linux for reference.

    • Go to Jenkins > Manage Jenkins > Configure System
    • Check “Environment variables”
    • add name: ANDROID_HOME, value -> your android sdk dir
    • click “add”
    • SCROLL DOWN CLICK SAVE

    It just looks like the Android SDK on your jenkins box does not have the “Android Support Repository” component installed.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.