1

I'm using Android Studio and I'm trying to integrate FireBase in my application. For that, I need to add dependencies in both project's root build.gradle and module's build.gradle. But I understand that there's only one build.gradle in my project. When I added everything (dependencies for FireBase) in the same build.gradle, it wasn't working.

So I understood it has something to do with build.gradle. Here's the project structure screenshot .Probably the project was imported from eclipse. Is there any way I can have 2 build.gradle files without creating the project again?

This post has similarity with Android Project Structure is incorrect; only one build.gradle. Please dont mark it as duplicate. Because in the above link, the answer was to go with a single build.gradle. But in my case I need 2 build.gradle to proceed further. Since I don't have enough reputation, i couldn't comment on that post. Sorry.Please help.

here's how my only build.gradle looks like :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        //FireBase dependency
        //classpath 'com.google.gms:google-services:3.0.0'
    }
}
apply plugin: 'android'



dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    //FireBase dependency
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
}
//FireBase
//apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 21
    buildToolsVersion '23.0.3'
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
        }
        arm {
            ndk {
                abiFilters "armeabi-v7a", "armeabi"
            }
            minSdkVersion 19
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/notice.txt'
    }
    defaultConfig {
        minSdkVersion 19
        applicationId "com.nytshift.eym.pas"
    }
}
Community
  • 1
  • 1
Rakesh
  • 1,205
  • 1
  • 14
  • 33
  • Guys, Could somebody please help me? – Rakesh Dec 16 '16 at 06:59
  • are you using Android stuido or eclipse ? – animal Dec 16 '16 at 09:46
  • @animal, I'm using Android Studio. The project may have been imported from an eclipse. I believe thats why I have only one build.gradle. I would like to have another one as well. – Rakesh Dec 16 '16 at 09:54
  • have you selected the project structure as `Android` or `Project` ? – animal Dec 16 '16 at 09:56
  • @animal Both ways. In the screenshot mentioned in the post, it was project structure. Please check the link of another post I mentioned in regard to build.gradle. Fabio has said 2 build.gradles can be generated. – Rakesh Dec 16 '16 at 10:02
  • @Fabio has commented it can be converted to 2 gradle files. – Rakesh Dec 16 '16 at 10:03
  • are you importing it properly ? i know this might sound lame but i want to know the process you are following – animal Dec 16 '16 at 10:06
  • @animal, The project has been imported long back and not in the recent past. Everything works fine now. It's just that I need that extra build.gradle file inorder to move ahead with the FireBase since FireBase needs play services dependency to be added in the build.gradle. – Rakesh Dec 16 '16 at 10:10
  • So your problem is solved ? – animal Dec 16 '16 at 10:10
  • @animal, Nope it's not solved. I need to have 2 build.gradle files in my project. so that FireBase dependencies can be added in those two. Currently I have only one build,gradle. – Rakesh Dec 16 '16 at 10:11
  • @animal, Take a look at Fabio's comment : http://stackoverflow.com/questions/38688292/android-project-structure-is-incorrect-only-one-build-gradle#comment64968811_38792481 – Rakesh Dec 16 '16 at 10:21

1 Answers1

0

You have two gradles. You need to change the view of the filesystem from the top left. Change it to "android"

enter image description here

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Deep Gupta
  • 11
  • 1