2

I'm creating an Android app. I've named it app. I've to add below dependency in app module's build.gradle file:

implementation 'com.firebase:firebase-jobdispatcher:0.5.0'

But, I don't want to type it manually by editing build.gradle file. I want a way, so that I can search it and select it from some list. I want to do so to avoid any typo error or version related issue.

To achieve it I went to Project Structure window of the Android project > app module > Dependencies tab (Refer screenshot)

enter image description here

I opened Add Library dependency window. This window can be opened from the drop down menu which we get after clicking + button in green (Refer screenshot). I tried to search com.firebase keyword in Add Library dependency window. But I don't get the desired dependency in the list. What should I do?

RBT
  • 24,161
  • 21
  • 159
  • 240
  • Your answer has **definitely** helped me. That is the reason why I upvoted your post as it gave me the pointers to move in a direction where there is likelihood of getting the desired solution. I still don't know how to add `jcenter` repository in my project though. If you feel that your post could cause confusion for the community then please feel free to purge it but I can't accept it as the accepted answer if it _hasn't_ solved OP's key concern. – RBT Jan 25 '20 at 23:57

2 Answers2

1

After digging around, I found that when we enter any keyword for dependency in the "Choose Library Dependency" dialog, by default it searches for the artifacts present in the Maven Central repository only (as mentioned below the input field), so only the dependencies available there will be listed down as result.

Since, the artifact com.firebase:firebase-jobdispatcher:0.5.0 is only present in jcenter repository, so it could not resolve it through maven central repo.

You can verify the results yourself by going on both the repositories and searching for firebase-jobdispatcher.

enter image description here

Note: I couldn't find any way to add jcenter or any other repositories in addition to maven central for this search dialog.

Qasim
  • 5,181
  • 4
  • 30
  • 51
  • You've mentioned good pointers in your post. Now I need to figure out about adding jcenter repository in my project. Currently it is searching only in Maven central. – RBT Sep 05 '18 at 07:04
  • I can see my project's `build.gradle` file shows jcenter being included in the repositories being referred - `buildscript { repositories { jcenter() google() }` – RBT Sep 05 '18 at 07:15
  • yes, that's for gradle, but studio doesn't know about it, which is why when you add dependency through gradle script, it works but not otherwise. – Qasim Sep 05 '18 at 07:16
0

You need to include dependency into your build.gradle file

    compile 'com.google.android.gms:play-services:10.2.1'
    compile 'com.google.firebase:firebase-messaging:10.2.1'

And put below line at the end of build.gradle file

apply plugin: 'com.google.gms.google-services'

Then Write your App level Gradle like this:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Steps to integrate Firebase into your Project Link

If you want to add a dependency from in-built List then you need to go from:

  • Click on File --> Project Structure
  • Select App from Module --> Click on Dependency Tab
  • Click on plus Icon then Click on Library Dependency
  • Then display dependencies that into yous SDK
  • Select dependency which you want otherwise you need to put manually in Build.gradle.

Hope this may help you.

InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • 1
    Op is asking to add dependency using module settings UI in studio, not manually editing gradle files – Qasim Sep 05 '18 at 06:13
  • Yeah but this answer may help to him to setup firebase simply. – InsaneCat Sep 05 '18 at 06:15
  • Thanks for the help. But firebase dependency is just an example as correctly pointed out by @Qasim . I often face this issue whenever I've to add a new dependency in my Android project. I want to do it from UI so that I can also see if there are multiple versions of any given dependency which I can point to. – RBT Sep 05 '18 at 06:19