Plugin gradle in android studio don't work - android

I want use gradle plugin in android studio.
I added classpath in build.gralde:
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
and
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
I put my map api key in local.properties (MAPS_API_KEY = "mykey") and use it on my manifest:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
My app run succefully But it's don't work for me.

I didn't see you mention it, but when you specify a variable such as ${MAPS_API_KEY}, a value has to be provided that will be substituted later.
For your case, Google recommends using the "local.properties" file. Add an entry there of:
MAPS_API_KEY = your key value
So that the ${MAPS_API_KEY} can be populated with your actual key.

Related

Fabric crashlytics new implementation not working | fabric.properties

The implementation to put the apiSecret and apiKey in the fabric.properties file isn’t working anymore.
Fabric properties file: app/fabric.properties
apiSecret=xx68f6074dxxxxxc11dxxx97c172e8ebf0
apiKey=xxxe76c4xxxx97e8cxxxx0135e9d46f5a2xxx
Add to .gitignore (for open source projects)
Remove the entry at the AndroidManifest.xml:
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxx6c41xxx6ec601xxxd4xxxa2" />
Official documentation: https://docs.fabric.io/android/fabric/settings/working-in-teams.html#android-projects
Does anymore know what have changed or why this isn’t working anymore?
The issue appears to have been fixed (at least for me) with version 1.31.0 (July 24, 2019) of the Fabric Gradle plugin:
classpath 'io.fabric.tools:gradle:1.31.0'
Now when building an App Bundle the AndroidManifest.xml file includes the io.fabric.ApiKey meta-data element.
https://docs.fabric.io/android/changelog.html#july-24-2019

Problems adding Firebase Crashlytics to Android project - Crashlytics found an invalid API key: null

I am trying to add Firebase crashlytics to our project but just can not get it to work.
I have followed the instructions adding the necessary lines to our gradle file but no success so far.
The main issue I get is this message:
Crashlytics found an invalid API key: null
which seems weird since I thought an API key should not be needed for Firebase.
I use Android studio 3.0.1 with the latest gradle plugin. My project is Ionic based but I have tried to hand modify the gradle file as well with the same results.
I had a similar problem and it turned out that I did not apply google-services plugin in the bottom of build.gradle (in app module)
apply plugin: 'com.google.gms.google-services'
After that it is working
There is an incompatibility with some other Firebase libraries that add the API key in the manifest for you, for example com.firebaseui:firebase-ui-auth:2.3.0
You can check with the Merged Manifest in Android Studio, to see if that is the case:
The issue might be resolve by updating/removing the library if possible, otherwise you can remove the API key by adding a <meta-data> tag with a tools:node="remove" attribute, like this:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your.package">
<application
...>
<meta-data
android:name="io.fabric.ApiKey"
tools:node="remove"/>
</application>
</manifest>
This will tell the manifest merger that you don't want this specific meta-data.
# Fabric properties file: app/fabric.properties
apiSecret=x8x6x5x54x4xx8xxxx98 #your api hash
apiKey=xx389xxx8xx7x787x8x7x78x78x9x #api key
if you added api key in manifest remove it

Android Marshmallow error:GoogleService failed to initialize, status: 10, Missing an expected resource: [duplicate]

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

Crashlytics found an invalid API key - AndroidStudio build

I saw all other questions, but none of accepted answers is working for me.
By following integration steps found here https://dev.twitter.com/twitter-kit/android/integrate I have created crashlytics.properties file in module root. File is filled with apiKey and apiSecret values found in my newly created twitter application.
Error occurr on project build. I am using AndroidStudio 1.0
This is my error:
ERROR - Crashlytics Developer Tools error.
java.lang.IllegalArgumentException: Crashlytics found an invalid API key: REAL_APIKEY_VALUE.
Check the Crashlytics plugin to make sure that the application has been added successfully!
Contact support#fabric.io for assistance.
You just forgot to add one line, in app-level gradle file.
apply plugin: 'com.google.gms.google-services'
this happens because when you are adding firebase:crashlytics, firebase document not have this line. so you need to add it manually. see this is firebase:crashlytics document photo.
This happened to me when I updated Android Studio from 3.2 to 3.3, to fix it I just updated the
classpath 'com.google.gms:google-services:4.1.0'
to
classpath 'com.google.gms:google-services:4.2.0'
And it worked again
Works fine added this on fabric.properties like this:
# Fabric properties file: app/fabric.properties
apiSecret=xx68f6074dxxxxxc11dxxx97c172e8ebf0
apiKey=xxxe76c4xxxx97e8cxxxx0135e9d46f5a2xxx
Add on .gitignore (for open source projects)
REMOVE entry on AndroidManifest.xml:
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxx6c41xxx6ec601xxxd4xxxa2" />
Oficial documentation: https://docs.fabric.io/android/fabric/settings/working-in-teams.html
I also experienced this issue and it took a while for me to realize I forgot adding the following line into the app/build.gradle:
apply plugin: 'com.google.gms.google-services'
After adding it, it started working like a charm even without <meta-data> in manifest and/or app/fabric.properties file.
Add the below line in app/build.gradle file
apply plugin: 'com.google.gms.google-services'
Clean The Project and Run.
after adding file fabric.properties, getting error as below.
Crashlytics found an invalid API key: null.
Check the Crashlytics plugin to make sure that the application has been
added successfully!
Contact support#fabric.io for assistance.
We need to register app and verify SHA-1 for same.
Add firebase: add google-services.json file from firebase console to your /app folder of your application.(follow steps given by Firebase Console-> Add Firebase to your Android app )
It's not giving error now
<meta-data android:name="com.crashlytics.ApiKey"
android:value="YOUR_API_KEY"/>
Add this one on Android manifest.xml
here you get the api key
https://www.fabric.io/kits/android/crashlytics/install
If someone is using crashlytics with Android dynamic features module, make sure your fabric and google-services plugins are applied only in your app module. In my case that was the problem.
Changing the below dependency at project build.gradle from :
classpath "com.google.gms:google-services:4.1.0"
to
classpath "com.google.gms:google-services:4.2.0"
has solved the problem for me.

How can I hide my Google Maps API Key when sharing my code on github?

My Android application is OpenSource, and I am a little bit afraid to share the code on Github, because my API keys were also shared.
I can git ignore my strings.xml file, but I really hope there is an alternative and I will be able to do something clever, so I wont have to worry about it.
Any idea or suggestion?
Customize the ant build script of your project to generate a mapskey.xml (strings) from local.properties (which you add to git ignore).
Those who fork just create their own local.properties with debug and release keys for Google Maps.
Put the key in a separate file and read it from there, and only commit a placeholder file to the repository.
In android studio put your API key and secrets in the local.properties file.
In your top-level settings.gradle file, include the Gradle plugin portal, Google Maven repository, and Maven central repository under the pluginManagement block. The pluginManagement block must appear before any other statements in the script.
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
In Android Studio, open your project-level build.gradle file and add the following code to the dependencies element under buildscript:
plugins {
// ...
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
}
Open your module-level build.gradle file and add the following code to the plugins element.
plugins {
// ...
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}
Save the file and sync your project with Gradle.
Open the local.properties in your project level directory, and then add the following code. Replace YOUR_API_KEY with your API key.
MAPS_API_KEY=YOUR_API_KEY
Save the file.
Access the key within AndroidManifest.xml file:
In your AndroidManifest.xml file, go to com.google.android.geo.API_KEY and update the android:value attribute with MAPS_API_KEY as follows:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
Access the key within Java/Kotlin code: Just use BuildConfig as follows:
BuildConfig.MAPS_API_KEY
More can be found in docs.
If strings.xml is required by the program, then it should be included in the source, but strings specific to each user of the source should be left out. In their place, provide documentation on where the specific strings should be included.

Categories

Resources