To simplify things I'm going to call the libraries I'm using library_a.aar and library_b.aar.
Here is the scenario that I'm facing.
library_a is build and pushed to maven_repository and no problems here.
library_b depends on library_a and added to library_b as follows:
repositories {
maven {
credentials {
username USERNAME
password PASSWORD
}
url "https://api.bitbucket.org/1.0/repositories/COMPANY/maven_repository/raw/releases"
}
}
dependencies {
...
compile 'package:library_a:1.0'
...
}
library_b is built with no errors and uploaded to the maven_repository.
Now my application depends on library_b which I need to add by providing (as above) the repository along with the credentials.
The first issue that I'm facing is that in order to compile library_b in my project it needs to be compiled in the following way:
dependencies {
...
compile 'package:library_b:1.0#aar'
...
}
I have to add the #aar otherwise gradle won't recognize it, but I didn't have to do that with library_a.
The second issue is that when I build the app I get warnings that it can't find references to classes available in library_a. What am I missing over here? I did try to add transitive=true to library_a
dependencies {
...
compile ('package:library_a:1.0') {
transitive = true;
}
...
}
but absolutely nothing works. I did check the pom file and it includes the proper dependencies.
Could it be that what I'm doing is not supported by gradle and I have to compile both library_a and library_b in my app?
Sounds like your maven repo only contains the aar files but no or wrong pom files.
Are you using the following gradle plugin and the uploadArchives gradle task in order to upload the aars to your maven repository?
https://github.com/dcendents/android-maven-gradle-plugin
try this gradle snippet for your aars:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android { ... }
dependencies { ... }
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://api.bitbucket.org/1.0/repositories/COMPANY/maven_repository/raw/releases") {
authentication(userName: USERNAME, password: PASSWORD)
}
}
}
}
Then use the uploadArchives gradle task
Related
I wanted to integrate my own library to an Android application.
Before I push it on remote maven repo I want to check the integration with an application locally. So I've pushed it to my mavenLocal().
Maven was installed via brew install maven
And there is my problem - Gradle cannot resolve dependency to my library.
Error I get is just ERROR: Failed to resolve: com.op.rlgen:0.0.1
In library I use maven-publish plugin:
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
groupId 'com.op'
artifactId 'rlgen'
version '0.0.1'
artifact("$buildDir/outputs/aar/rlgen-release.aar")
pom.withXml {
// generating pom logic here
}
}
}
// For `publish` task use mavenLocal
repositories {
mavenLocal()
}
}
to publish a library on my maven I use:
./gradlew :rlgen:publishToMavenLocal
In following path i have 2 files, one with aar extension, the second one with pom:
~/.m2/repository/com/op/rfgen
As I thought the problem is caused because of quite complicated scripts in my main app, I created a sandbox, clear Android Application.
In sandbox's gradle I have:
// project level
allprojects {
repositories {
mavenLocal()
google()
jcenter()
// also tried with
maven {
url "~/.m2/repository"
}
}
}
// app level
dependencies {
compile('com.op.rfgen:0.0.1#aar) {
transitive = true
}
}
I check if mavenLocal points to proper folder and it seems ok:
// in gradle
repositories {
println(mavenLocal().url) // file:/Users/op_user/.m2/repository/
}
And with this configuration I cannot add dependency to that aar because of:
ERROR: Failed to resolve: com.op.rlgen:0.0.1:
Affected Modules: app
Thanks for your help!
The problem was that line:
compile('com.op.rfgen:0.0.1#aar). Should be... compile('com.op:rfgen:0.0.1#aar)... :D
I want to use Segment (with Firebase) into my NativeScript app. So I must follow this instructions : https://segment.com/docs/destinations/firebase but I must modify two files : the Module-level build.gradle :
buildscript {
dependencies {
// Add these lines
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
and the Project-level build.gradle :
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
}
But with NativeScript I have only one build.gradle. So, how can I implement this lines in gradle ?
Thanks !
I know this question is old but they may help someone in the future. Nativescript Docs aren't the best and this worked for me so it MAY not work for you.
This applies for Plugins and Regular Apps.
Buildscript Gradle.
App_Resources/Android/buildscript.gradle
PLUGINS buildscript.gradle
repositories {
// Add this line
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.google.gms:google-services:3.1.0'
}
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.segment.analytics.android.integrations:firebase:+'
}
apply plugin: 'com.google.gms.google-services'
HOWEVER
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.https://docs.gradle.org/current/userguide/java_library_plugin.html
You can also write this as
App Grade
PLUGINS include.gradle
App_Resources/Android/app.gradle
dependencies {
implementation 'com.segment.analytics.android:analytics:4.+'
implementation 'com.segment.analytics.android.integrations:firebase:+'
}
Here is how my application module 'app' build gradle looks like:
apply plugin: 'com.android.application'
repositories {
maven { url 'http://localhost:8080/repository/internal/' }
}
...
dependencies {
compile 'org.apache.httpcomponents:httpmime:4.2.3'
compile 'com.testpackage.networking:networking:1.0.3'
}
and it works just fine. I'm trying to use same dependency in my library module named 'librarymodule'. Here is how its build.gradle looks like:
apply plugin: 'com.android.library'
repositories {
maven {
url 'http://localhost:8080/repository/internal/'
}
}
...
dependencies {
compile 'org.apache.httpcomponents:httpmime:4.2.3'
compile 'com.testpackage.networking:networking:1.0.3'
}
The only difference is gradle plugin 'com.android.library' used here vs 'com.android.application' used in 'app' module.
Error:A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.testpackage.networking:networking:1.0.3.
Searched in the following locations:
https://jcenter.bintray.com/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom
https://jcenter.bintray.com/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar
file:/Users/myusername/Library/Android/sdk/extras/android/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom
file:/Users/myusername/Library/Android/sdk/extras/android/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar
file:/Users/myusername/Library/Android/sdk/extras/google/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom
file:/Users/myusername/Library/Android/sdk/extras/google/m2repository/com/testpackage/networking/networking/1.0.3/networking-1.0.3.jar
Required by:
LibrariesApplication:app:unspecified > LibrariesApplication:librarymodule:unspecified
So, for some reason there is no http://localhost:8080/repository/internal/com/testpackage/networking/networking/1.0.3/networking-1.0.3.pom under Searched in the following locations list.
It's not only my repository problems. I can for example use
maven { url 'https://mint.splunk.com/gradle/' }
repository with dependency
compile 'com.splunk.mint:mint:4.1'
and still getting similar error
Does anyone knows how to fix that?
This is a bit strange but adding custom repository to 'allprojects' of root build.gradle actually worked!
allprojects {
repositories {
jcenter()
maven {
url 'http://localhost:8080/repository/internal/'
}
}
}
If you don't want to put the maven credentials in the project file (and you shouldn't), create a "gradle.properties" file in your home directory and put the maven credentials in that file, like:
mavenUser=myUser
mavenPassword=myPassword
Then, in your build.gradle file, use as follows:
maven {
credentials {
username mavenUser
password mavenPassword
}
url http://my.maven.url
}
What is the preferred way to share some code (E.g. a Utils class) between two projects when building two apps using Gradle to build?
Can I do this without creating extra jar files? I just want my code to sit outside the app projects, be imported/compiled into both app projects. Or is this simply not possible?
I'm familiar with the approach that uses jars or Android library projects, but both seem a bit unwieldy.
My favorite way of doing this is by keeping it in a local Maven repo. The repo can even live in your SCM so it's the same across workspaces.
Create a new Android Studio project and then set it as a maven project your build.gradle config:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
repositories {
mavenCentral()
}
configurations {
archives {
extendsFrom configurations.default
}
}
group = 'com.mypackage.mylibrary'
version = '1.0.0'
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: uri("relative/path/to/localrepo"))
pom.project {
artifactId 'mylibrary'
name 'My Library'
packaging 'aar'
}
}
}
}
android {
// copy old android config here
}
You'll need to deploy the library before you can use it. Do this by using the uploadArchives task [./gradlew uploadArchives]
Now you should be able to use this library in any project by doing this:
repositories {
maven { url 'relative/path/to/localrepo' }
}
dependencies {
compile ('com.mypackage.mylibrary:1.0.0')
}
When you make changes to your library, you'll have to re-deploy (uploadArchives) with a new version, then update the dependency reference in whatever project needs the new version.
Im trying to build a simple android app using gradle build tools. but im getting an error like this
No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT]
Possible solutions: module(java.lang.Object)
ang here's a simple configuration of build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
compile 'org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
processResource {
expand (project.properties)
}
task configureDebug << {
jar.classifier = "debug"
}
task configureRelease << {
proguard.enabled = true
}
When applying a plugin you want tell you build script to use it in its classpath. It is not required for compilation so just change the configuration compile to classpath. More more information see 51.5.1. Using your plugin in another project in the Gradle user guide.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.0-SNAPSHOT'
}
}
EDIT: At the moment the plugin does not support r20 of the Android SDK. For more information see this issue.
Make sure you are writing the dependency block on your application build.gradle "YourProjectName->yourprojectname->build.gradle" in android studio hierarchy .
Use android gradle tools
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}