I am trying to develop an Android app using Pubnub's realtime API facilities. As per the documentation we need to add a gradle dependency line below within the build.gradle file:
compile 'com.pubnub:pubnub:4.1.0'
Strangely enough, Gradle is not able to satisfy this dependency. My repository configuration within the Gradle build script is as follows:
repositories {
jcenter()
}
I tried adding mavenCentral() instead of jcenter() but still no luck. Any help would be greatly appreciated.
Please note: I am adding only the relevant sections of the build.gradle file since I do not have the authority to paste the whole build script.
Also, this is my first time with the Android ecosystem - hence any help in pointing out obvious newbie errors would be great.
Did you right click on app, go to Open module settings, click on the Dependencies tab, click on the +, choose add module dependency and then ok?
Related
I want to add AdView to my activity and I click on download and then it automatically implements the necessary library. But then I get the following error:
Error 1
I get the same error when I try to add GridLayout to my library.
Here is my gradle file: gradle file
I already tried to set the Global Gradle settings to offline work but it doesn't help.
I have android studio 3.4.2
This is a problem that bothers me for a while now and there seems no solution to this. Is it possible that these things are not available for androidx yet? Thank you for your help!
From the documentation:
To make the Google Play services APIs available to your app:
Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
Add a new build rule under dependencies for the latest version of play-services, using one of the APIs listed below.
Ensure that your top-level build.gradle contains a reference to the google() repo or to maven { url "https://maven.google.com" }.
Save the changes, and click Sync Project with Gradle Files in the toolbar.
You can now begin developing features with the Google Play services APIs.
This is often a common mistake. If you have multiple repositories in your gradle, make sure that maven google is at the top of the list.
eg.
repositories {
maven { url "https://maven.google.com" }
...
}
This package:
// https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads
implementation "com.google.android.gms:play-services-ads:18.1.1"
is either available from repository google() or from repository mavenCentral():
repositories {
google()
mavenCentral()
...
}
see the quick-start.
I have an strange issue. I just pulled our master branch and I am the only developer who get following error message among many Android developers in my company.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':bookingcore-android:debugCompileClasspath'.
> Could not find play-services-ads-identifier.jar (com.google.android.gms:play-services-ads-identifier:15.0.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-identifier/15.0.1/play-services-ads-identifier-15.0.1.jar
we have following in root build.gradle file
repositories {
google()
jcenter()
...
}
and in one of our modules:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
dependencies {
....
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"
}
Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1. Is there anyway to tell gradle to download play-services-ads-identifier.jar from this link rather than google maven?
Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1
No, that is a Web page. Among other things, it contains:
Note: this artifact it located at Google repository (https://maven.google.com/)
On my Android Studio 3.1.4 installation, like your coworkers, I am having no problems with:
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"
when I have google() listed in allprojects { repositories {} } in the root build.gradle.
For some reason, your Android Studio seems to think that this is a JAR, when it is really an AAR.
Tactically, you can force the issue, by changing the line to:
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1#aar"
However, that is treating a symptom, not whatever the underlying problem is.
If you want to try fixing the underlying problem, try these:
If you have not done so already, do Build > Clean Project, and see if it picks up the AAR (I doubt that this helps, but it's always a good first step)
If that does not help, try File > Invalidate Caches/Restart, and see if it then picks up the AAR
You can try to clear the build cache if you are using Gradle 3.3 or higher, then see if it picks up the AAR
If that does not help, you can try closing Android Studio, renaming ~/.gradle/caches (or the equivalent on Windows) to something else, re-opening Android Studio, and seeing if it then picks up the AAR as it re-downloads all of your dependencies (if this works, you can delete the renamed directory; if it fails, you can always restore the renamed directory)
I have a project hosted on GitHub at https://github.com/BoardiesITSolutions/NavigationDrawerManager.
I've seen some projects on GitHub state adding it to their gradle file in Android Studio to the dependencies section but this doesn't seem to be working for me.
I have tried compile: 'com.github.boardiesitsolutions.NavigationDrawerManager:+' but it keeps saying it can't find it, I've also tried replacing the + with the version number but no luck, Android Studio keeps saying it can't find it. I've added the repository MavenCentral as well.
Is there something I need to do from GitHub to make it accessible for Gradle?
I don't see it on maven.
You can use this website to use non-mavenized libraries with Gradle.
Just add maven { url "https://jitpack.io" } to repositories section of build.gradle and use compile 'com.github.BoardiesITSolutions:NavigationDrawerManager:0b14c84445' in dependencies.
I have read a lot answers related to this topic, but none of them have worked to solve my problem, so need help with this:
I need to import a .aar file into a project created with Android Studio 1.1.0, I have imported it using the "New Module" option and actually I don't receive any error, I can build the application and run it, but when I try to use a class from this .aar file Android Studio doesn´t find the reference to it, let's say it can´t recognize the package that I want to include in my code.
You are maybe thinking that I must add the dependency, I have already done that, It seems to not work.
So someone could tell me which is the correct way to import and use a .aar file in Android Studio 1.1.0
To import an .aar library:
Go to File>New>New Module
Select "Import .JAR/.AAR Package" and click next.
Enter the path to the .aar file and click finish.
Go to File>Project Structure (Ctrl+Shift+Alt+S).
Under "Modules," in left menu, select "app."
Go to "Dependencies" tab.
Click the green "+" in the upper right corner.
Select "Module Dependency"
Select the new module from the list.
After reading a lot of answers on Stackoverflow, I found the solution for my problem, I want you to know which were the steps I followed in order to reproduce it:
Add a .aar file in my libs folder.
Use "New Module" option under File menu.
Import the .aar file.
Build gradle and compile the project.
When I tried to use the new module in my app, It didn't recognize any class inside the new module.
The problem is related to the version of Gradle, I was using 1.1.0 and there is a bug in this version, so my suggestion is to change the version to 1.0.1, there is an Issue already open in order to fix this problem https://code.google.com/p/android/issues/detail?id=162634
You should change the version in the build.gradle file located in the root of your project.
buildscript {
repositories {
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
You can find additional information about this problem here https://groups.google.com/forum/#!topic/adt-dev/1Ho_c8dALQQ
I guess in version 1.2.0 this problem will be solved.
I follow steps in both answers but finally I need to add this line to my build.gradle:
allprojects {
repositories {
mavenCentral()
flatDir { dirs 'aars'} // this line
}
}
Use the gradle dependency
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
I already saw this question, but it is not helping me. First of all, I tried to add google play services in my project using:
dependencies{
compile 'com.google.android.gms:play-services:6.5.87'
}
It was showing me error:
Then I updated my studio to 1.0.1 and gradle to 1.0.0. And then I again synced the project with gradle. And it worked! It showed me another option despite of two options shown in above screenshot. It was "Install the library"(something like that). I clicked it and it popped up a dialog, and I installed the library(it was like downloadind using SDK manager and not like gradle downloads).
Now, I tried to download this library using:
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
And it gives me error:
My android repository is updated:
Also, my internet connection is working fine. I tried to sync project many times, but same error all the time. I am not running gradle in offline mode:
How to fix this? And what is the permanent solution? And why is all this happening?
I found this question: Studio failed to download library from gradle repository which describes the exact same error, and that question had this bit of build script that you need to add to the build file that has the dependency statement in question:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
When I do this, it works for me.
As to the general question of why this happens (and the better question of why the solution is different for different libraries):
Gradle, the build system that Android Studio uses, has the ability to automatically download library dependencies from the Internet. By and large this is a big boon for developers, because instead of having to manually download archive files, put them in the right place in your project, check them into source control, and repeat the process for new versions, now you just have to add a line of build script and the build system takes care of the housekeeping for you. The major downsides are Internet connectivity woes, which affect different developers to different degrees, and some added confusion about what it means when you get an error.
How does Gradle know where to download dependencies? Most Gradle build scripts contain a block that looks like this:
repositories {
jcenter()
}
or it may be mavenCentral() instead of jcenter(). This tells the build system to look in the JCenter or Maven Central global repositories (and JCenter is in a simplistic way of thinking about it a value-added mirror of MavenCentral); these contain archives of many versions of many, many, many libraries and are very convenient to use.
You can specify other repositories as well. This swipelistview library hasn't been uploaded to Maven Central, so the developer has made a repository for it available via a URL: if you add that URL to your repositories block, it will look for it there.
I was worried about the fact that you're accessing a SNAPSHOT version of the library -- these are supposed to be unpublished by definition. But adding a dependency on the snapshot version of the library in my test project worked for me, and looking around that URL in a web browser reveals that there's only a "1.0-" (trailing dash included) version of the library, so there's some subtletly there I'm missing; if you know more, please edit my answer or comment.
In any event, there are a couple caveats to this explanation. Some libraries aren't on Maven Central or on any Internet-accessible archive (at least they're not officially published by Android), but are instead published as part of the Android SDK download and maintained via the SDK manager. The Android support libraries and Google libraries fall under this category. If you get errors about those not being found, you have to fix it via the SDK manager.
How does the build system know to look in the SDK for those, since you didn't tell it via the repositories block? This behavior is hardcoded into the Android Gradle plugin.
The other caveat is that there's a detail that trips up a lot of people, which is that you actually have two repositories blocks, though with the usual Android Studio setup they're often in different files. One is in a buildscript block, which usually lives in the top-level build.gradle file and looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other often also lives in the top-level build.gradle, but you can augment it with another block in your module's build.gradle file. The top-level one looks like this:
allprojects {
repositories {
jcenter()
}
}
and a module-level one would look like one of the previous examples in this answer. What do all of these mean?
The buildscript block tells Gradle where to find build system plugins. These are plugins that enhance the functionality of the build system itself but don't say anything about your actual project. In Android projects, the Android Gradle plugin is in this category, and unlike the Android/Google libraries, this one does live on Maven Central. The repositories block (in coordination with the dependencies block, which is not the same as the dependencies block for your project, keep reading) in buildscript tells the build system where to go look for these plugins.
The allprojects block in the top-level build file tells the build system to apply the bit of contained script to all build files in the project. In this example, it's telling it to add a repositories block pointing to JCenter to all subprojects. This is a convenience so you don't have to copy/paste it into multiple build files in your modules.
In your modules, you also have a repositories block, which in conjunction with the allprojects thingy, tells the build system where to go to get library dependencies for your project, as was previously discussed.