Gradle cannot resolve local aar dependency - android

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

Related

How we can link two interdependent projects in Android studio 3.6?

I have a sdk and a client app. The client app is using the sdk. When I build the sdk, it generates multiple aar files which I can add it in libs folder in my client project.
Now if I modify the sdk, every time I need to build the sdk code using gradlew and then add the aar in client code. This is becoming a lengthy process.
My top level build.gradle file looks like below:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.2'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Is there a way to link the sdk code with client code. So the sdk changes will be automatically picked by the client code. I am using Android Studio 3.6.
Thanks,
Arindam.
you can use the maven, or maven-publish to publish to your own maven repositories, it can be local. the config like that in build.gradle
uploadArchives {
repositories {
configuration = configurations.archives
mavenDeployer {
// the local repo address
repository(url: uri('../repo'))
pom.project {
version '1.0.1'
artifactId 'artifactId'
groupId 'groupId'
packaging 'aar'
description 'version 1.0.1'
}
}
}
}
then add this repository in project build.gradle
maven {
url "file://Users.../yourProject/repo/"
}
after that, you can use that as the third library. after you change it, you only need to execute it, then build the current project.
if you also want to look at the source code about SDK in the current project.
you can change to use maven-publish plugin.

Android Studio not resolving dependencies for app engine module

I'm trying to follow the tutorial here: https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio to create a Google App Engine Module. I followed the first step to use the UI to generate an App Engine Module, but after that I got stuck on the part about adding dependencies. When I try to use File > Project Structure > + > Add Library Dependencies, none of three dependencies listed in the tutorial show up in the list of available libraries. After reading other StackOverflow posts, I tried the following:
I updated Android Studio, Android Build Tools, Google Play services, and the Google Repository to the newest version.
I tried adding the dependencies manually by writing compile statements in the backend module build.gradle file (e.g. compile 'com.google.appengine:appengine-api-1.0-sdk'). Then the sync failed and Android Studio gave me the following error: Failed to resolve: com.google.appengine:appengine-api-1.0-sdk
I tried File > Restart / Invalidate Cache
I tried using Android Studio on a different computer
All this, yet no success. Below are my gradle files, in case they are of use. Although I would be surprised if they would be, since I just followed the app engine part of the tutorial.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
backend module build.gradle:
// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk'
compile 'com.google.firebase:firebase-server-sdk'
compile 'org.apache.httpcomponents:httpclient'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
Android Studio gives me the error message mentioned above on the last three dependencies in the above file when I try to sync. Any help would be appreciated. Thanks.

Nested aar dependencies not working

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

In Android, compiling with Gradle, how to share code between projects?

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.

Building android project with gradle

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'
}

Categories

Resources