How to include the third library in .arr with JCenter? - android

In my android library project I include many third-party libraries like
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
// Java8的时间库
compile 'com.jakewharton.threetenabp:threetenabp:1.0.3'
// RxJava
compile 'io.reactivex:rxjava:1.1.5'
compile 'io.reactivex:rxandroid:1.2.0'
when I used ./gradlew install build arr not include this third library. So my other project can't reference this library.
but when I include Rosie project (https://github.com/Karumi/Rosie). I can auto include dagger, butterknife....
How can I do it?
I want my library to include these third-party libraries in my arr.What can i do?

You must include these lines in your build.gradle to use Butterknife :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'

Related

How(is it possible) to add a dependency to my android library(aar)? [duplicate]

We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

How to pack an .aar that has an external dependency? [duplicate]

We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Gradle: exclude dependencies from inside an aar [duplicate]

We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Gradle errors while adding dependencies in build.gradle

I've tried to included cards library in my project using the below code in my build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
//Core card library
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
//Optional for built-in cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
//Optional for RecyclerView
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
//Optional for staggered grid view support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
//Optional for drag and drop support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
//Optional for twowayview support (coming soon)
//compile 'com.github.gabrielemariotti.cards:cardslib-extra-twoway:2.0.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
But when compiling, android studio is throwing up errors as below.
Error:(23, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'cardslib_1' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
I'm guessing the reason to be gradle version, which is lower in libraries I'm including.
How to know the gradle version my dependencies are using and how to adjust them to my project.
When I thought to add the libraries, maven has repositories in aar file which I don't think will let you know the gradle version.
Thanks for any help in this regards.
You're adding the dependencies in the wrong place. They should be outside of the buildscript section and in the modules/applications build.gradle.
Parent build.gradle. This should be in the root directory of your project
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Module build.gradle. This should be in the folder of the module you're trying to add the dependencies to.
apply plugin: 'com.android.application'
android {
// Android related settings go here
}
dependencies {
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
}
This assumes that the structure of your project is something like
Project
|___build.gradle
|___Module
|____build.gradle

How to use the "provided" keyword in gradle's build.gradle dependencies

I'm new to gradle. Please help me understand how to use the keyword "provided" that is in build.gradle dependencies block.
And what is the difference between this "provided" with "providedCompile" and "providedRuntime"?
build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
...
dependencies {
def presentationDependencies = rootProject.ext.presentationDependencies
def presentationTestDependencies = rootProject.ext.presentationTestDependencies
compile project(':domain')
compile project(':data')
apt presentationDependencies.daggerCompiler
compile presentationDependencies.dagger
compile presentationDependencies.butterKnife
compile presentationDependencies.recyclerView
compile presentationDependencies.rxJava
compile presentationDependencies.rxAndroid
provided presentationDependencies.javaxAnnotation //what is this???
...
}
EDIT
The project in question has no mention of
configuration {
provided
}
and it still compiles!
The project is Android-cleanArchitecture
TIA
Gradle has no built in support for the provided dependency scope.
However this blog (credit goes to Danny, the blog's writer) describes how it can be emulated.
In short you need to provide a new configuration named "provided":
configurations {
provided
}
Then add this configuration to the relevant source sets configurations:
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
And finally you're good to go:
dependencies {
provided <your dependency>
}
Note that according to the blog post if you're using Eclipse there's a "major flaw" but the post also provides a workaround for that.

Categories

Resources