Add Firebase gcm to project - java

I want to add Firebase to my project to use push notifications
at home I implemented it by adding this line at build.gradle (app)
apply plugin: 'com.google.gms.google-services'
and this line at my build.gradel (project):
classpath 'com.google.gms:google-services:3.0.0'
and it worked .
At work for proxy reasons i'm not able to connect to jcenter and getting this error :
Unknown host 'jcenter.bintray.com'. You may need to adjust the proxy settings in Gradle.
so i cant build the project
I need a way to implement this without the plugin and classpath
I'm using
compileSdkVersion 23
buildToolsVersion "23.0.3"
my depndecies :
dependencies {
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.android.gms:play-services:9.6.1'
}
And is there a way to add the play-services classes to the gradel cash to be able to work offline
NOTE:
I have tried to update to sdk 24 and build tool 24.0.3
and not use thouse tow lines but i kept geting the error that fire base was never initialized and i need to use this:
firebase.initializeApp(context)
I did use in the application context but did not work
NOTE 2 :
My build.gradel (project) has jcenter as a repository
repositories {
jcenter()
}

Add below code in build.gradle(project)
repositories {
jcenter()
}

Related

Plugin with id 'com.android.application' not found cannot evaluate the root project [duplicate]

This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:
Error:(1, 0) Plugin with id 'com.android.application' not found
C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.bob.helloagain6"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.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:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Updated Answer (Dec. 2, 2020)
Latest Gradle: 6.5
Version check:
./gradlew -v
How to update:
Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
Update: ./gradlew wrapper
Latest Android Gradle Plugin: 4.1.0
If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.
buildscript {
repositories {
google() // For Gradle 4.0+
maven { url 'https://maven.google.com' } // For Gradle < 4.0
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.
Original Answer
I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.
The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.
This can happen if you miss adding the Top-level build file.
Just add build.gradle to top level.
It should look like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.xx.y'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.
Root-gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
In the project level build.gradle file, I have replaced this line
classpath 'com.android.tools.build:gradle:3.6.3'
with this one
classpath 'com.google.gms:google-services:4.3.3'
After adding both of those lines, and syncing, everything became fine.
Hope this will help someone.
I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)
This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.
The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.
Finally, I figured out that it was my following mistake:
I tried importing a specific Application alone instead of importing the application along with dependent library projects.
The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)
I found the problem after one hour struggling with this error message:
I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.
Renaming it to build.gradle resolved the issue!
I still got the error
Could not find com.android.tools.build:gradle:3.0.0.
Problem: jcenter() did not have the required libs
Solution: add google() as repo
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
}
}
I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result.
Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.
Go to your grade file where you can see this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
And change classpath to this:
buildscript {
repositories {
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.
However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.
So, you should just avoid the duplication or conflict.
For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.
This issue happened when I accidently renamed the line
apply plugin: 'com.android.application'
on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.
[FOR FLUTTER] go to your build Gradle then check if you have three paths
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I somehow removed the android tools classpath and was getting the error.
This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.
If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html
Then open "as existing project" in Visual Studio
Gradle is very finicky about this.
I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:
//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new
I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.
In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:
./gradlew --refresh-dependencies
This caused the newer version of gradle to be re-downloaded and the error no longer occurs.
Check the spelling, mine was 'com.android.aplication'
This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.
i had similar problem and i did following things to resolve it.
i referred to https://developer.android.com/studio/build
and copy / pasted these following lines before apply plugin lines
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
module app build.gradle file
apply plugin: 'com.android.application'
model{
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId "com.iamsafe"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled = false
useProguard = true
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.2'
compile files('libs/asmack-android-8-0.8.10.jar')
compile files('libs/commons-io-2.0.1.jar')
compile files('libs/httpclient-osgi-4.2.1-sources.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.1.2.jar')
}
project build.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.10'
}
}
allprojects {
repositories {
jcenter()
}
}
In this case of issues check below code
dependencies {
classpath 'com.android.tools.build:gradle:**1.5.0**'
}
and gradle-wrapper.properties inside your project directory check below disctributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
If these are not compatible with each other then you end up in this issue.
For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
If you work on Windows , you must start Android Studio name by Administrator.
It solved my problem
Just make sure you put the http and https proxy correctly when you create the app

Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage(). (Android Studio)

I'm trying to build this old app on the newest version of Android Studio that requires Gradle 1.10. I keep getting sync errors (See below).
SYNC ERROR:
Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Consult IDE log for more details (Help | Show Log) (8 s 599 ms)
What versions/numbers should I have in my lines that are marked with ***.
buildscript {
repositories {
mavenCentral()
}
dependencies {
**** classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'android'
repositories {
mavenLocal()
mavenCentral()
}
android {
*** compileSdkVersion 19
*** buildToolsVersion "19.1"
defaultConfig {
*** minSdkVersion 10
*** targetSdkVersion 19
}
lintOptions {
abortOnError false
}
}
dependencies {
*** compile 'com.android.support:appcompat-v7:19.1.0'
*** compile 'com.bitalino:bitalino-java-sdk:1.0'
*** compile 'org.roboguice:roboguice:3.0b-experimental'
*** compile 'com.squareup.retrofit:retrofit:1.5.0'
}
Kept getting this error when I tried to import a file for a class I'm taking. Several days of digging and a little luck later, learned about gradle versions and Android Gradle Plug in versions. The numbers are not the same but they must correspond as per the table in this link: https://developer.android.com/studio/releases/gradle-plugin After I got that then I had to go into the build.gradle file and change it to this. My changes are annotated
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
buildscript {
repositories {
google()//Add this
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'//change to this
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()//add this
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and in the griddle-wrappers.properties file change
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
If you look at the table in the link you will see that the 4.1.0 in this build.gradle file line
classpath 'com.android.tools.build:gradle:4.1.0'
matches the 6.5-all in this gradle-wrapper.properties line
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
I didn't try it but I would imagine that as long as the numbers correspond to each other on the chart then it would work even if it weren't exactly these numbers.
Hope this helps you out.
Try updating the Android Gradle plugin to the latest available version:
Change
classpath 'com.android.tools.build:gradle:1.5.0'
to
classpath 'com.android.tools.build:gradle:2.3.2'
Yes indeed - however the IDE does not seem to know the latest version. I go with the latest versions when I get this type of error but IDE creates an error message that is not useful. We know the house is on fire and ee want to how to put it out...

Failed to resolve firebase-database-15.0.0

I'm currently getting an error on android studio: http://prntscr.com/lebil3
I'm obviously a noob. It has something to do with Firebase, which I connected to my app with some errors, but it did connect successfully.
I checked the link you had given and your implementation looks like this:
implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
I think the problem is the last 15.0.0 part. That should not be there. It should be just 16.0.1.
Also try adding this to your app build.gradle:
implementation 'com.google.firebase:firebase-core:16.0.1'
If this doesn't work, in your project level build.gradle file, check if you have:
classpath 'com.google.gms:google-services:4.0.1'
and the plugin at the bottom of your app level build.gradle:
apply plugin: 'com.google.gms.google-services'
If none of this has worked, check out this documentation by Firebase on adding Firebase to your Android app.
Hope this helps!
Please add google() on Project Bluild
allprojects {
repositories {
google()
}
}
Change implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0' to
implementation 'com.google.firebase:firebase-database:16.0.4'. I had the exact same problem a few days back. If that still does not work, compare your other dependencies with mine and adjust accordingly.

android studio failed to create new project

I am new in android app development, and this a month that I am working with android studio. Before, I created lots of project without any problem. This is two days that I received this strange error when I create a new project:
Error:Unable to find method 'org.apache.http.impl.client.DefaultHttpClient.setRedirectStrategy(Lorg/apache/http/client/RedirectStrategy;)V'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I also uninstall android studio and install it again but still doesn't work well, and also my previous projects don't work with this new android studio.
this is how my build.gradle looks like:
// 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:1.5.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
}
android {
compileSdkVersion 22
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
}
productFlavors {
}
}
dependencies {
}
and this is the screen shot:
I suppose that, you're trying to use already unsupported library
HttpClient is not supported any more in sdk 23.
You have to use URLConnection or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0')
If you need SDK version 23, add this to your build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
You also may try to download and include HttpClient jar directly into your project or use OkHttp instead.
If you need more information, please check also related topics:
Android libraries not found
HttpClient won't import in Android Studio
How to use the legacy Apache HTTP client on Android Marshmallow?
EDIT: According to How to exclude libraries from all dependencies in Gradle
configurations {
compile.exclude group:'ch.qos.logback'
}
or
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
Check this: android studio: gradle dependency error
Hope it help
Based on these explanations, the solution is to remove httpClients libraries from java exra libraries for me (on mac) form following dir:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext

Error: Could not find com.google.gms:google-services:1.0. when adding google service plugin in build.gradle in android studio

I am integrating OAuth login for Google+ on my android application, following the tutorial.
According to the tutorial, I should add the Google Service plugin by adding
classpath 'com.google.gms:google-services:1.0' dependency to top-level build.gradle in my android project.
However, when I sync the gradle with the changes, I see the error as follows:
Error:Could not find com.google.gms:google-services:1.0.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.jar
https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.pom
https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.jar
In my build.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:1.2.3'
classpath 'com.google.gms:google-services:1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
It seems that the android studio is not able to find google-services plugin from repositories.
Does anybody have the same issue? Or, am I missing something?
I ran into the same issue today. In the samples they use this line instead:
classpath 'com.google.gms:google-services:1.3.0-beta1'
This works.
For me I had to switch the repository to jcenter(). I was using mavenCentral and getting this error. As soon as I switched to jcenter() it pulled the dependency down.
To do this, open your build.gradle and replace each instance of mavenCentral() with jcenter()
Google updated their guide. Where it was classpath 'com.google.gms:google-services:1.0' now reads classpath 'com.google.gms:google-services:1.3.0-beta1' like joluet suggested.
Google now released the plugin v1.3.0
I was able to solve it using this:
classpath 'com.google.gms:google-services:1.3.0'
I resolved this issue by doing the following things:
In build.gradle (at project level):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In build.gradle (at module level):
On top added:
apply plugin: 'com.google.gms.google-services'
and in dependecies added:
compile 'com.google.android.gms:play-services-analytics:8.3.0'
Apart from this make sure you have updated the Google Play services and Google repository in the SDK.
As of 25th Nov,2015, google released a newer version.
Try adding:
classpath 'com.google.gms:google-services:2.0.0-alpha1'
And don't forget to add jcenter() repository under buildscript.
Thanks.
I think you forgotten gradle's project level,
From developers page:
Add the dependency to your project-level build.gradle
classpath 'com.google.gms:google-services:1.5.0-beta2'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Google has updated GCM go check it and for that you have to update your Android Studio too.
I would advise you against doing what you are doing. I did it too (by following Set up a GCM Client App on Android blindly) but ended up with exceeding 65K method limit.
So, you should remove the following lines from your gradle:
apply plugin: 'com.google.gms.google-services'
classpath 'com.google.gms:google-services:1.0'
Now import APIs of Google Plus with simple gradle import:
compile 'com.google.android.gms:play-services-plus:8.1.0'
Adding jcenter repository to project level build.gradle helped in my case:
buildscript {
repositories {
jcenter();
mavenCentral()
}
I was trying to setup firebase for my android app when I faced this problem. Following screenshot should clarify things -
Couple of things I would like to point out -
1. Once you
apply plugin: 'com.google.gms.google-services'
This line should be at the bottom of the app level gradle file. Not sure why but putting at the top did not workout for me.
If you use Android Studio, try to add google service with the IDE.
Right click on folder module.
On left list at Developer Services choose desired service.
Wait for syncing and the IDE will automatically add google dependecies.
add classpath on buildscript
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:1.3.0-beta1'
}
}
You maybe miss this step
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project. Open the Android Studio Terminal pane:
$ move path-to-download/google-services.json app/
Have fun.
You need to check the current version as in the link below says, by now:
classpath 'com.google.gms:google-services:1.3.0-beta4'
Check this answer:
Update gradle version
We have to look for the last version in my case was:
dependencies {
classpath 'com.google.gms:google-services:1.4.0-beta3'
}
Here you can find a list of the versions.
I got a similar problem while following the instructions for implementing a GCM client in Android Studio, however, the message I got was :
Error: Could not find com.google.gms:google-services:1.3.0-beta1...
Although I never figured out what was wrong, I simply copied my sources, resources, manifest, and keystore into a new Android Studio project. I then edited the auto-generated gradle build files for the new project by manually re-adding my dependencies.
I made sure not to copy over my build files from the old project verbatim (since the source of the error likely lay in them somewhere).
It is not a satisfying solution, but it worked for me and it took little time.
For me adding this under dependencies worked
compile 'com.google.gms:google-services:3.0.0'
Inside the .idea folder exists a workspace.xml file that defines the project's structure. I suggest you to close Android Studio, then delete .idea folder and then import the project again. The .idea would be generated by the IDE again. For me this solution works.
You should just add classpath 'com.google.gms:google-services:1.3.0-beta1' to dependencies of your (Top level build file) the build.gradle that has the (Project:<name of your project). Hope this helps!
I recently updated to Android Studio 2.3 and somehow apply plugin doesn't work.
After that, I tried various ways and then what work is when I commented out app's build.gradle:
apply plugin: 'com.google.gms.google-services'
and then I add this to top-level build.gradle (below classpath 'com.android.tools.build:gradle:2.2.3'):
classpath 'com.google.gms:google-services:3.0.0'
and then it works.

Categories