0

I'm very new working with android and dependency management with Gradle. I'm a developer from Java and usually I used Maven to manage the dependencies.

Investigating I found that Gradle is now the dependency management on Android. I usually work with layer on the server side. I did a client project to communicate with the client side that in case is a Android Application. I have to add my client jar as dependency in the Android Project.

Actually I have my local repository with Archiva. In pom.xml usually I declared my local repository in the repositories tag, with this, I can include my projects as dependency.

Is possible do this with Gradle?

I did this, but when I run the project in the android emulator the project fails.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

// Build Configuration
buildscript {
    // Repositories
    repositories {
        mavenLocal()
        mavenCentral()
    }
    // Dependencies
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

// Android Plugin
//apply plugin: 'android'
apply plugin: 'android-library'

// Repositories
repositories {
    mavenLocal()
    mavenCentral()
}

// Dependencies Configuration
dependencies {
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2'
    **compile 'com.project:myproject-client:1.0.0'**
}

// Android Configuration
android {
    buildToolsVersion '20.0.0'
    compileSdkVersion 20
    sourceSets {
        main {
            manifest {
                srcFile 'app/src/main/AndroidManifest.xml'
            }
            java {
                srcDir 'app/src/main/java'
            }
            res {
                srcDir 'app/src/main/res'
            }
            /*assets {
                srcDir 'assets'
            }*/
            resources {
                srcDir 'app/src/main/resources'
            }
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    lintOptions {
        // simple xml fails lint checks because it references javax.xml.stream
        abortOnError false
    }
}
Jorge Alvarez
  • 293
  • 2
  • 4
  • 15

1 Answers1

0

You'll need to declare your Archiva repository.

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url 'http://hostname/rep' // replace with url to your internal repo
    }
}
Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
  • I tried that but when I rebuild the project I have the error: package com.mycompany.package doesnt exist. I'm using Android Studio – Jorge Alvarez Sep 05 '14 at 15:29
  • If you run `gradlew dependencies --configuration compile` is your dependency listed there? – Mark Vieira Sep 05 '14 at 15:32
  • Yes, but when I rebuild the project and deploy into the Android Emulator, It doesn't load because the my dependency is not loaded into the apk. – Jorge Alvarez Sep 05 '14 at 15:50
  • Try the solution mentioned in the comment http://stackoverflow.com/a/21134305/957630. – Mark Vieira Sep 05 '14 at 16:04
  • Thanks, The solution that works from me is adding the dependency to the libs directory into my android application, also adding the dependency in gradle and works fine, I don't know if this is fine because the problem that I see is that I have to copy each time the jar into the folder libs and not is automatically. – Jorge Alvarez Sep 05 '14 at 17:26