3

I am trying to start the Friendly Chat Firebase tutorial. But the gradle build throws an error and I can't really give anymore information as I don't know where to begin. However, a picture is worth a thousand words, and I believe that it contains everything relevant.

  • Files downloaded from git google.json copied across
  • Dependencies added and applied
  • Build tools and IDE updated

I noticed there is only a project build.gradle I cant find a module build.gradle. I have no idea if this has anything to do with the issue though.

Originally threw error about unregistered VCS root, I clicked add root, but it didn't help.

enter image description here

Both build.gradle files are blue and when I click either one, it opens the tab named android-start(also blue), but the path is C:\Users\User1\friendlychat\android-start\build.gradle and the file contents are:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

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


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    }
}

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

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

EDIT: LogCat says configure Android SDK

If I click configure and set the SDK version and build tools version I get:

Error:(31, 0) Could not find method android() for arguments     [build_coejwo2h3fxgj0snev4rovui4$_run_closure4@512b9d86] on root project 'android-start' of type org.gradle.api.Project.
<a href="openFile:C:\Users\User1\friendlychat\android-start\build.gradle">Open File</a>
AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    "cant find a module build.gradle"... Your picture clearly shows `app/build.gradle` and `/build.gradle` or your project. Please show them here as text with an [edit] – OneCricketeer Oct 05 '16 at 15:18
  • Thanks, edited. where does it say that it cant find build.gradle/ – Nathan Waddington Oct 05 '16 at 15:30
  • And the other one, please? Can you also click "show log in explorer" and see what is in there? – OneCricketeer Oct 05 '16 at 15:50
  • There is only the one gradle file it opens the same thing, in logcat it says configure SDK – Nathan Waddington Oct 05 '16 at 16:17
  • If it says to configure the SDK, then that means you need to open the SDK Manager and configure it – OneCricketeer Oct 05 '16 at 17:09
  • its been working fine in past projects, I think the problem maybe because I downloaded from github rather than created the project, Im not sure how to manually setup the SDK, I clicked configure before and set the build tookls version and sdk version but then I get a different error see edit – Nathan Waddington Oct 05 '16 at 17:36

1 Answers1

9

I think the error is in project.gradle... I explain about it, this dependencie is correct because is inside the project.gradle:

classpath 'com.google.gms:google-services:3.0.0'

The other dependencie that needs firebase, needs is inside app.gradle:

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

And the app.gradle needs too this dependence:

compile 'com.google.firebase:firebase-core:9.6.1'

The finally gradles are these, project.gradle:

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


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    }
}

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

And the app.gradle:

...

dependencies {
    compile 'com.google.android.gms:play-services:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
}

//At final of the document
apply plugin: 'com.google.gms.google-services'

Tell me if I can helps you, greetings!

  • Please can you explain where these gradle files are, Normally I see them at the bottom under "Gradle Scripts" but in this file I have only the one, there is a second build.gradle in my project source files, but they both open the same file as shown in the picture and OP I downloaded this from Firebase Codelabs , I kind of expexted it to work out of the box as I havent even started the tutorial yet – Nathan Waddington Oct 05 '16 at 17:04
  • @NathanWaddington Both files are actually called `build.gradle`, and there are two of them. They can clearly be seen in the image you have in your post – OneCricketeer Oct 05 '16 at 17:08
  • Exactly @NathanWaddington, the first one is *app.gradle* as *build.gradle* from app folder and the other one is *project.gradle* as *build.gradle* from project folder. Tell us about this changes, greetings! – Merlí Escarpenter Pérez Oct 05 '16 at 17:13
  • This is where I am struggling, no matter which one I click on, it opens the same file in an android-start tab (as shown in picture) – Nathan Waddington Oct 05 '16 at 17:29
  • Ok, with your view in the gradle scripts has 2 gradles as *build.gradle* this names has a extensions name *(Project: YourProject)* at first and *(Module: app)* open both and see their structure, then follow my up indications. – Merlí Escarpenter Pérez Oct 05 '16 at 17:35
  • Brilliant I did what you said, I had to open the project navigation 'app' drawer, the other gradle file was in there, once I had updated what you had said, the gradle file jumped back down under the Gradle Scripts section, I have no idea why or how tho , and why did it not work from the start, is that a problem from firebase? – Nathan Waddington Oct 05 '16 at 17:46
  • Just realised I had had it in project view and not android view, which is why I couldnt find the gradle file, I still don't understand why it didnt work from the start – Nathan Waddington Oct 05 '16 at 17:54
  • @MerlíEscarpenterPérez Why at the end of the document. That does not make sense, there have to be a reason. – AXSM Mar 02 '17 at 17:54
  • @AlexSanchez because the documentation say it: https://firebase.google.com/docs/android/setup – Merlí Escarpenter Pérez Mar 03 '17 at 08:52