简体   繁体   English

在Android Studio上设置Firebase

[英]Setting up firebase on Android studio

I am trying to setup firebase on my android studio.I am using a 2.2.3 version.So this is my code in app.gradle file: 我正在尝试在Android Studio上设置Firebase,我使用的是2.2.3版本,所以这是我在app.gradle文件中的代码:

   apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.parth.carpool"
            minSdkVersion 22
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-a`enter code here`nnotations'
        })
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile 'com.google.firebase:firebase-core:16.0.1'
        testCompile 'junit:junit:4.12'
    }
    apply plugin: 'com.google.gms.google-services'

This is the error that I am receiving. 这是我收到的错误。

Error:(27, 13) Failed to resolve: com.google.firebase:firebase-core:16.0.1

This is my project.gradle file: 这是我的project.gradle文件:

    // 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.2.3'
        classpath 'com.google.gms:google-services:4.0.0'

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

To correct this error I installed google play services, google repository, SDK platform,SDK platform tools etc. after I saw some of the posts on stackoverflow. 为了更正此错误,我在stackoverflow上看到了一些帖子后,安装了Google Play服务,Google存储库,SDK平台,SDK平台工具等。 Does anybody have a solution? 有人有解决方案吗?

First you need to upgrade android studio to the newest version: 首先,您需要将android studio升级到最新版本:

If you're not using Android Studio 3.1 to develop your app, you will need to upgrade in order to get the correct version checking behavior within the IDE. 如果您未使用Android Studio 3.1开发应用程序,则需要进行升级才能在IDE中获得正确的版本检查行为。

https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html

Then you need to use the following top level gradle file: 然后,您需要使用以下顶级gradle文件:

buildscript {
 repositories {
      google()
      jcenter()
  }



dependencies {
 classpath 'com.android.tools.build:gradle:3.1.3'
 classpath 'com.google.gms:google-services:4.0.1'
 }
}

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

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

Android Studio provides Awesome tool called Firebase Assistant, it handles any thing you need to setup firebase in you'r project Android Studio提供了一个称为Firebase Assistant的强大工具,它可以处理您在项目中设置Firebase所需的任何事情

from Tools->Firebase 工具-> Firebase

在此处输入图片说明

just pick which product you want and it'll do all the work for you 只需选择您想要的产品,它将为您完成所有工作

Make sure you are connected to a good network 确保您已连接到良好的网络

Goto >file -> other settings -> Under build, execution, and deployment -> you will see Gradle. 转到>文件->其他设置->在构建,执行和部署下->您将看到Gradle。 uncheck the checkbox offline work. 取消选中复选框离线工作。 Then rebuild your project. 然后重建您的项目。

 buildscript {
repositories {

    // add google here
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:4.0.0'

}
}

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

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

Did you try on this link 您是否尝试过此链接

In your root build.gradle file add the repo: 在您的root build.gradle文件中,添加仓库:

maven { url "https://maven.google.com" }

这取决于您要如何设置,可以尝试设置Firebase的显式方式和隐式方式。最简单的一种是android studio中提供的隐式方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM