I am integrating GCM into my app, what i did was i have made the configuration file google-services.json and placed it inside the app folder (i am using Android Studio) the resource file is also imported and I am also including the plugin in my build.gradle of application like this
apply plugin: 'com.google.gms.google-services'
the problem is that it is still not resolved. I want to know what is wrong?
I have searched about it and i find this, i have used my project number now there is no error coming up. Is it right way to do? Someone please explain
Take a look at the gradle files of the official google example: https://github.com/googlesamples/google-services/tree/master/android/gcm
You will see you need to do two things:
add
classpath 'com.google.gms:google-services:2.0.0-beta6'
to project gradle build file and
apply plugin: 'com.google.gms.google-services'
at the bottom of module app gradle build file.
Related
I'm trying to create an Android library for two days already.
Realy need your help.
I have an existing App which I want to do as a Library.
According to Android developers documentation:
f you have an existing app module with all the code you want to reuse,
you can turn it into a library module as follows:
Open the module-level build.gradle file. Delete the line for the
applicationId. Only an Android app module can define this. At the top
of the file, you should see the following: apply plugin:
'com.android.application' Change it to the following: apply plugin:
'com.android.library'
I have done this step.
The next step is saying:
When you want to build the AAR file, select the library module in the
Project window and then click Build > Build APK.
I don't really understand how to build the AAR file.
Also in my library, I have others dependencies which I need to be in my Library.
I tried a lot of suggestions in StackOverflow but didn't find the answer.
Unfortunately, I didn't find a good example of creating an Android Library with dependencies.
I don't really understand how to build the AAR file
Just compile the library or use ./gradlew build.
The output will be stored under the library's subdirectory under build/outputs/aar.
I have others dependencies which I need to be in my Library.
The aar file doesn't contain the transitive dependencies.
I suggest you publishing your library into a public or private maven repository.
This question already has answers here:
Error "File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it" [duplicate]
(23 answers)
Closed 2 years ago.
File google-services.json is missing. The Google Services Plugin cannot function
I get this error code since I deleted my google-services.json file from my project. Now the obvious way to solve this issue would be to include it again, but I had a reason to remove it.
"Note: If you enabled only Google Sign-In when you generated the configuration file, you can skip this step. Google Sign-In does not require the configuration file to be included in your project—generating the file performs the neecessary configuration steps." - this is the official note in the documentation and since I only enabled Google Sign-In I don't see a reason for this error message. Does anyone have had this problem too and a solve to it because I think that I implemented everything correctly.
Note: It works with the file in the project included.
EDIT: To clarify, my application works completely fine and I have no problems, but I wondered why I cannot remove the google-services.json file even though I should be able to do it with no problem!
When you add apply plugin: 'com.google.gms.google-services' inside your app-level build.gradle it parses configuration information from the google-services.json file.
You removed google-services.json file, that's why it is not able to parse So remove the below line too from your app-level build.gradle who triggered parsing to make it work again.
apply plugin: 'com.google.gms.google-services'
You are using Google signin right? So u definitely need a google-services.json file
Refer this link
https://developers.google.com/identity/sign-in/android/start-integrating
Add the dependency to your project-level build.gradle:
classpath 'com.google.gms:google-services:3.0.0'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
The gradle-plugin google-services that is referenced by classpath and with apply is a build-time plugin only! So it only influences the build-process of your app, but not the runtime-process!
Thats why your app is working fine but google-services json is required.
Has the same effect add the "apply plugin" at the beginning or end of the file build.gradle in Android Studio projects?
For example to add the 'com.google.gms.google-services' plugin, Firebase official documentation recommends adding at the end, but I've seen other codes add it at the beginning.
I know the question seems irrelevant, but I'm developing a plugin for Android Studio to manage dependencies and have this doubt.
Thanks in advance
Gradle scripts are interpreted top to bottom so order can be important. Keep in mind that gradle has a configuration phase and an execution phase so sometimes order isn't important. It's common to apply your plugins at the top of the script since plugins often add extension objects and tasks to the gradle model which can then be configured lower down in the build script.
For example, you can't do the following because the test task is added by the java plugin:
test {
include 'org/foo/**'
}
apply plugin: 'java'
I am using google Maps in my android application. I have created the key and added necessary permissions in manifest file. But soon I start the application I get this message in debugger:
GoogleService failed to initialize, status: 10, Missing an expected
resource: 'R.string.google_app_id' for initializing Google services.
Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin.
I am not sure whats wrong. The Map is working fine and I can use it without any issues. My gradle file has this entry:
compile 'com.google.android.gms:play-services:8.4.0'
What is it complaining about and how do I alleviate it?
[From Product Manager # Google]
You can fix this issue by downloading and copying the google-services.json file for your Android app by following the steps below:
Select your app/project name and Android packagename from this link and click Continue to Choose and configure services.
Click Continue to Generate Configuration files.
Download google-services.json and copy the file to the app/ or mobile/ module directory in your Android project.
If you have previously imported your Google project into Firebase, you can
get the updated google-services.json from the Firebase console under Project Settings.
DO NOT COPY the PROJECT_NUMBER as suggested by one of the other answers since the google_app_id refers to your app within a Project and not the project itself.
You need to place the configuration file (google-services.json) generated by developer.google.com, as mentioned in the 2nd step of the official docs here
The process is simple
You can select your project or create a new one.
Then after selecting desired services (in this case the maps service), you can generate the configuration file.
For people who have migrated to the Firebase projects they can get the same by going to Firebase Console, selecting your project and under settings you will find the configuration file.
Then as quoted in step 3 of the official docs here
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android
P.S : For people downvoting this answer, please do leave a comment as to why you are down voting it.
In my case, the cause of this error was that the Google Services plugin for Gradle and the Play Services library were incompatible versions. Instructions for compatible versions:
1) Add the dependency to your project-level build.gradle:
classpath 'com.google.gms:google-services:1.5.0-beta2'
2) Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
3) If you're using Android Studio, this is the string to add to the dependency section of your application's build.gradle file:
dependencies {
compile "com.google.android.gms:play-services:8.3.0"
}
Source: https://developers.google.com/cloud-messaging/android/client
I met the same problem and solved it followed the official solution.
Here are the steps:
get the configuration file google-services.json from this link.
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.
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'
Add this dependency to your app-level build.gradle:
dependencies {
compile "com.google.android.gms:play-services:8.3.0"
}
For those who face this problem even after correctly setting up play services and placing google-services.json file in project/app folder, the actual solution is to
Build > Rebuild Project
Possibly due to the fact that strings from json file are not integrated into compiled resources until a full rebuild is performed.
For Xamarin/Visual Studio Mac I needed to add this to the bottom of my Droid.csproj
<Target Name="ProcessGoogleServicesJson" Condition=" '#(GoogleServicesJson)' != '' AND '$(AndroidApplication)' == 'True' AND '$(DesignTimeBuild)' != 'True'" BeforeTargets="$(ProcessGoogleServicesJsonBeforeTargets)" AfterTargets="$(ProcessGoogleServicesJsonAfterTargets)">
<Message Text="Using ProcessGoogleServicesJson override" Importance="high" />
<ProcessGoogleServicesJson GoogleServicesJsons="#(GoogleServicesJson)" IntermediateOutputPath="$(IntermediateOutputPath)" MonoAndroidResDirIntermediate="$(MonoAndroidResDirIntermediate)" AndroidPackageName="$(_AndroidPackage)">
<Output ItemName="_AndroidResourceDest" TaskParameter="GoogleServicesGeneratedResources" />
<Output ItemName="FileWrites" TaskParameter="GoogleServicesGeneratedResources" />
</ProcessGoogleServicesJson>
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)\ProcessGoogleServicesJson.stamp" />
</ItemGroup>
https://github.com/xamarin/GooglePlayServicesComponents/issues/64
This also happen to me. In my case, it is because Android studio tried to insert some code to my main activity. Removing the code fixes the error
Inserted code is about App Indexing:
https://developers.google.com/app-indexing/android/publish
I had the same issue back then. Was able to solve it by using only the necessary play services library, which in my case GCM.
Instead of com.google.android.gms:play-services:8.4.0, I use com.google.android.gms:play-services-gcm:8.4.0. See here for more info; this also solves multidex problem.
Then I applied both #Radix and #Alexander's approach to remove the message GCM has been output in the logcat regarding the google-services.json.
You can change the versionCode and versionName of your app in your Gradle file.
A quick fix I used is to disable signing. If you aren't wanting to create production code you can set your build variant to debug, localOldDebug or localDebug.
Click on Build Variants on the bottom left in Android Studio.
how-to-disable-generated-signed-apk-android-studio
Just have another solution i'm remove accidentally
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Add this and work, is for new solution
I have a question very similar to Gradle build fails looking for Google Play Services in Android Studio
I have a working android project but when I add
compile 'com.google.android.gms:play-services:5.0.77'
I get a gradle build error
Error:Failed to find: com.google.android.gms:play-services:5.2.8
Open File<br>Open in Project Structure dialog
I have added the SDKs through the manager. Other threads have suggested that there might be a second SDK library on the computer causing the issue, but I have not been able to resolve this. I am using a mac (and normally a PC user so please bear with me) and looking at the SDK manager and the project structure dialog both say the SDK is located at:
/Applications/Android Studio.app/sdk
Given they are pointing to the same place it must be some other cause of the error?
Maybe I have a version other than 5.2.8 (although unlikely, as andoid studio says this is the most up to date and I have just updated the SDK)? How can I check the version installed on my machine - its not in the file names?
If you are going to use version 5.2.8 you have to set on your build.gradle
compile 'com.google.android.gms:play-services:5.2.08'
Because it is store on the directory :
ANDROID_SDK_PATH/extras/google/m2repository/com/google/android/gms/play-services/5.2.08
You can use '+' instead '08' and you will be using the last minor version
compile 'com.google.android.gms:play-services:5.2.+'
OK so it looks as though my version number was off and thats all that was causing the problem. If anyone else has this issue check your version number in the AndroidManifest.xml file in the google_play_services_lib directory
There is a problem with the 5.0.77 release version. Change com.google.android.gms:play-services:5.0.77 to com.google.android.gms:play-services:5.0.89 and things will work fine.
Google pulled out 5.0.77 from the Maven repository due to some critical bugs. Read More.
I had a different problem altogether. I'd put the line
apply plugin: 'com.google.gms.google-services'
at the start of the file. Even before:
apply plugin: 'com.android.application'
And had to scratch my head for half an hour.
So the final (working) condition looked like:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'