Are you using Jenkins server without access to internet for security reasons?
If you answer yes, then maybe you have experienced getting a compilation failure just because Jenkins is unable to find some dependencies.
Well one way to solve this problem is to put all the dependencies for the project in the libs directory.
But how do I know what are the jars, aars I need to include in the libs directory?
Umm, Gradle and maven have already define the way to solve dependencies, and transitive dependencies.
If you run the following command
gradle :app:dependencies
You will get a list with all the dependencies and transitive dependencies for the project. Then, Do I need to include all that dependencies one by one?, looking for them on Maven Central Repository, downloading the jar file and then copying into the libs folder. So much work, right.
Well, We can ask maven to help us with this task.
Step by step
- Install maven
- Add maven to the path
- Create a pom file with the following content:
- Get the dependencies and transitive dependencies. execute the following command:
- Copy the .jar and .aar files from the /tmp/temporalDirectory/ into the libs directory
- Register flat repository pointing to the libs directory
- Register jar dependencies and aar dependencies
- Create and install your apk
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mx.com.project</groupId> <artifactId>ProjectDependencies</artifactId> <version>1.0</version> <packaging>pom</packaging> <description>Project dependencies.</description> <repositories> <repository> <id>maven2</id> <name>Maven2</name> <url>http://repo1.maven.org/maven2/</url> </repository> <repository> <id>android-support</id> <url>file://${env.ANDROID_HOME}/extras/android/m2repository</url> </repository> </repositories> <dependencies> <!-- aar dependencies are coming from the repository ANDROID_HOME/extras/android/m2repository --> <dependency> <groupId>com.android.support</groupId> <artifactId>appcompat-v7</artifactId> <version>23.1.1</version> <type>aar</type> </dependency> <dependency> <groupId>com.android.support</groupId> <artifactId>design</artifactId> <version>23.1.1</version> <type>aar</type> </dependency> <dependency> <groupId>com.android.support</groupId> <artifactId>multidex</artifactId> <version>1.0.1</version> <type>aar</type> </dependency> <!-- jar dependencies are coming from maven central repository --> <dependency> <groupId>com.dubsmash.volley</groupId> <artifactId>library</artifactId> <version>1.0.20</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>de.greenrobot</groupId> <artifactId>eventbus</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>com.google.dagger</groupId> <artifactId>dagger</artifactId> <version>2.0</version> </dependency> </dependencies> </project>
Note the registration of a repository pointing to my file system where I have downloaded the android support repository. If you haven't installed the Android Support Library, open the SDK Manager and install it before executing the maven command.
mvn dependency:copy-dependencies -DoutputDirectory=/tmp/temporalDirectory/ -U
repositories { ... flatDir { dirs 'libs' } }
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name: 'appcompat-v7-23.1.1', ext: 'aar') compile(name: 'design-23.1.1', ext: 'aar') compile(name: 'multidex-1.0.1', ext: 'aar') compile(name: 'recyclerview-v7-23.1.1', ext: 'aar') compile(name: 'support-v4-23.1.1', ext: 'aar')
I was having a hard time trying to solve the dependencies for my project, I hope you don't have the same problem using this info as reference.
Always its an excelent información. ;-)
ResponderEliminarEste comentario ha sido eliminado por el autor.
EliminarThank you Erick
EliminarAlways its an excelent información. ;-)
ResponderEliminar