google analytics v4 integration to my android app - android

I have followed everything according to document provided by google, but am facing some issues, I have added google-services.json in root directory i.e in app.
Error:
Execution failed for task ':app:processDebugGoogleServices'.
No matching client found for package name 'com.google.samples.quickstart.analytics'
am getting this error. do help am working on android studio.

Try resolving the issue by adding the following line in the dependencies of the project-level build.gradle:
classpath 'com.google.gms:google-services:1.5.0'

Now Use like this in build.gradle:
com.google.android.gms:play-services-analytics:8.4.0
And follow this instructions:
Add Analytics to Your Android App
You can also generate configuration file from there
Follow the title: Add the configuration file to your project
Hope it will helpful for you.
EDIT:
Also please check if your build.gradle contains this line then remove it:
apply plugin: 'com.google.gms.google-services'

Seriously, Google should really make GA easier for all of us!!
Here's how I manage to get it work on buildToolsVersion '23.0.3' with com.google.android.gms:play-services:8.4.0
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId 'com.xxx.xxx'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/account',
'src/main/res/layouts/drawer',
'src/main/res/layouts/ntd',
'src/main/res/layouts/main',
'src/main/res/layouts',
'src/main/res'
]
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
I actually remove this line compile 'com.google.android.gms:play-services-analytics:8.4.0' and it still works.
top-level 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.0.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
// 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
}
GAV4 is really a pain in the axx, so I would also like to remind you somethings.
google-services.json
Official GAV4 Document tells you to generate google-services.json and put it under your project/app/ folder. However, it never says anything about this message.
AnalyticsService not registered in the app manifest. Hits might not be
delivered reliably. See google short url for instructions.
And I end up find the solution here analyticsservice-not-registered-in-the-app-manifest-error
json with flavor
If you are building a complex project, you might also want to use flavor for different json files. See the flavor config here google-services-json-for-different-productflavors?lq=1
xml app tracker
Yet, you would still have a hard time using xml to configure the tracker, so I also advice you to see this thread google-analytics-v4-string-xml-configuration-name-not-recognized-ga-trackingi
google_app_id
Finally, you would still see this message
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.
which you could find some discussion here googleservice-failed-to-initialize
In strings.xml, I do add R.string.google_app_id which is your project id in google api console, but I think it would still work even without it. I just want to get rid of that message from the log.
Wish you all good luck!

Related

Error: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:27.1.1 [duplicate]

I have searched around a lot but I cannot really find a post that helps I am somewhat new to android so some of this goes over my head. Anyway, my problems started when I got an error saying gradle plugin was old and the sync would not complete. So I changed a few things around not really sure what I did. Now I have:
Error(25,13) Failed to resolve: com.android.support:appcompat-v7 24.0.1
Project gradle file:
// 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.1.3'
// 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
}
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.bisesifreelance.maxbisesi.tic_tac_toe"
minSdkVersion 23
targetSdkVersion 24
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-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.1'
testCompile 'junit:junit:4.12'
}
Also I have installed all build tools in SDK manager I'm not allowed to embed images yet? but it says:
Android SDK Plaform-Tools 24.03 installed
Android SDK Tools 25.2.2 installed
Thank YOu! I'm very lost.
You can also write like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
try
compile 'com.android.support:appcompat-v7:24.2.1'
EDIT
For sdk 27
buildToolsVersion "27.0.3"
implementation "com.android.support:appcompat-v7:27.1.1"
Try adding jcenter like this way
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
Rather than
repositories {
jcenter()
}
Make sure that this folder exists:
\your-android-sdk\extras\android\m2repository\com\android\support\appcompat-v7\24.0.1
Of course, 24.0.1 should be replaced by the latest version.
I had this problem because I occasionally renamed 24.0.1 to something else and so the required folder couldn't be found.
I had the same problem after updating Android Studio. In my case it was an issue of permissions as I do my day-to-day programming on my user account, while Android studio was installed and updated with the administrator account.
FIX:
Open the standalone SDK manager and go down to 'extras'. Click on 'Android Support Repository' (which will probably set as 'Not installed') and install the packages. If you are prompted with an error message saying something like 'error trying to rename folder'. Go to the folder that is mentioned in the message and make sure that the permissions are set correctly. After that click 'Try Again' and it should install the package without a problem.
NOTE: This might happen a few more times. Just repeat the process for each file. The problem should then be solved.
Change a character - to :
compile 'com.android.support:appcompat-v7:24.2.1'
rather than
compile 'com.android.support:appcompat-v7-24.2.1'
try update the IDE and remove earlier build version (like 23) after installing later one and rename it to newer one.
Open SDK Manager and update the Extras-->Android Support Repository.
Path ..sdk\extras\android\m2repository\com\android\support\appcompat-v7>
Check for the updated version being installed.
In build.gradle in all projects, add Marvel and add this URL 'https://maven.google.com'

Android Studio Gradle Sync Error using google play-services-maps 11.6.2

I am developing a google map app using Android Studio. When I sync the project with Gradle Files (Select Tools/Android/Sync Project with Gradle Files on Android Studio), I get the following error:
Could not resolve com.google.android.gms:play-services-maps:11.6.2.
Couold not get resource 'https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-maps/11.62./play-services-maps-11.6.2.pom
This is the software I am using:
Android Studio 3.0.1
Android Version 7.1.1
Google Play Services 46
Google Repository 58 (under Support Repository)
I've tried using both the google maps project template and the empty activity project but I get the same error.
I am using the http proxy setup I used from earlier projects. I am able to install the play-services-maps and the google repository.
I also added the maven url to the Gradle Project file in the All Projects/Repositories section.
I have tried the suggestions from Stack Overflow but none have not worked.
Any ideas?
Gradle Project Build file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The gradle app build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "hansen.scott.googlemaps"
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-maps:11.6.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
The error is in the line:
implementation 'com.google.android.gms:play-services-maps:11.6.2'
try adding this in project level gradle file
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
Someone had the same issue I did and entered it on Stack Overflow a day or two ago. The user was getting a build error when using player-services-maps 11.6.2. If the user changed the version to 11.0.0, the build succeeded.
Once I back-dated the maps version to 11.0.0, this solved my problem too. I created a new Google Map project and didn't modify the Gradle Build files.
The problem appears to be that play-services-maps won't build using a versions after 11.0.0. I will post the issue on Github.
Thank you for everybody's help.
I have been facing the same issue for the past one week and posted it on Stack Overflow as well but to no effect.
I have since then figured out the root cause. I am working out of my office and thus have firewalls in place. I got it checked with the system admin and on turning off the firewall the build worked.
So i would advice you to have this checked as well.
Kind regards,
Kabir

Failed to resolve: com.android.support:appcompat-v7 24.0.1

I have searched around a lot but I cannot really find a post that helps I am somewhat new to android so some of this goes over my head. Anyway, my problems started when I got an error saying gradle plugin was old and the sync would not complete. So I changed a few things around not really sure what I did. Now I have:
Error(25,13) Failed to resolve: com.android.support:appcompat-v7 24.0.1
Project gradle file:
// 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.1.3'
// 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
}
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.bisesifreelance.maxbisesi.tic_tac_toe"
minSdkVersion 23
targetSdkVersion 24
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-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.1'
testCompile 'junit:junit:4.12'
}
Also I have installed all build tools in SDK manager I'm not allowed to embed images yet? but it says:
Android SDK Plaform-Tools 24.03 installed
Android SDK Tools 25.2.2 installed
Thank YOu! I'm very lost.
You can also write like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
try
compile 'com.android.support:appcompat-v7:24.2.1'
EDIT
For sdk 27
buildToolsVersion "27.0.3"
implementation "com.android.support:appcompat-v7:27.1.1"
Try adding jcenter like this way
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
Rather than
repositories {
jcenter()
}
Make sure that this folder exists:
\your-android-sdk\extras\android\m2repository\com\android\support\appcompat-v7\24.0.1
Of course, 24.0.1 should be replaced by the latest version.
I had this problem because I occasionally renamed 24.0.1 to something else and so the required folder couldn't be found.
I had the same problem after updating Android Studio. In my case it was an issue of permissions as I do my day-to-day programming on my user account, while Android studio was installed and updated with the administrator account.
FIX:
Open the standalone SDK manager and go down to 'extras'. Click on 'Android Support Repository' (which will probably set as 'Not installed') and install the packages. If you are prompted with an error message saying something like 'error trying to rename folder'. Go to the folder that is mentioned in the message and make sure that the permissions are set correctly. After that click 'Try Again' and it should install the package without a problem.
NOTE: This might happen a few more times. Just repeat the process for each file. The problem should then be solved.
Change a character - to :
compile 'com.android.support:appcompat-v7:24.2.1'
rather than
compile 'com.android.support:appcompat-v7-24.2.1'
try update the IDE and remove earlier build version (like 23) after installing later one and rename it to newer one.
Open SDK Manager and update the Extras-->Android Support Repository.
Path ..sdk\extras\android\m2repository\com\android\support\appcompat-v7>
Check for the updated version being installed.
In build.gradle in all projects, add Marvel and add this URL 'https://maven.google.com'

Where does the "compile" statement go in build.Gradle?

I needed to add a android.support.v4.widget.NestedScrollView to my project, which requires the V4 support library according to this question.
In the answer it said . . .
You need to add this line in dependencies:
compile 'com.android.support:support-v4:23.4.0'
...I assumed that referred to the build.gradle file. I have two - a top-level one and a module one. Only my top-level one had a dependencies keyword, so I put it there. But when I did I got
Error:(8, 0) Gradle DSL method not found: 'compile()'
...which is addressed in this question here as well as this question where it indicates I need to move it to the build.gradle for my module. But the module build.gradle has a completely different structure so I don't know where it goes.
My top-level build.gradle looks like this:
// 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.1.2'
compile 'com.android.support:support-v4:23.4.0'
}
}
allprojects {
repositories {
jcenter()
}
}
And my module-level one looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.assemblyguide.remote"
minSdkVersion 16
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Where do I put the compile statement (or the dependencies clause it goes into) in the module build.gradle to avoid that error, and why do the two build.gradle files look so completely different?
Bonus question: I'm new to Android Studio and I didn't have to know this stuff for Eclipse. How much of a Gradle expert should I plan to be to use Android Studio and where can I get a basic understanding of Gradle without having to get a PhD in it?
I suggest you download the full Gradle distribution, which comes with the "User Guide" PDF. Read it from top to bottom, skipping chapters that are truly not relevant to you. You'll avoid having to ask many questions.
Direct link to Gradle User Manual pdf
In your case, you should remove the "compile" line you added in the "buildscript" block. You likely need to replace your "allprojects" block with the following:
allprojects {
repositories {
jcenter()
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
}
}
You should declare the the dependencies at the end of your main project module. Usually it is the app module. Find a build.gradle file there and follow the instructions shown here
It should look like this one

How to enable Firebase Crash Reporting - Android

I followed all the steps on the docs to use Firebase Crash Reporting in my Android app (I use Android Studio and everything is up-to-date).
I used their own code to throw an exception to see if it works:
try {
throw new NullPointerException();
} catch (NullPointerException ex) {
FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
FirebaseCrash.report(ex);
}
And the console gives me this log:
E/MainActivity: NPE caught
V/FirebaseCrash: Firebase Crash Reporting is disabled.
Here is one 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.1.0'
// Firebase - Google Services 3.0.0
classpath 'com.google.gms:google-services:3.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
}
Here is the other build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-N'
buildToolsVersion '24.0.0-rc2'
defaultConfig {
applicationId "com.app.test"
minSdkVersion 19
targetSdkVersion 'N'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
useProguard true
}
}
}
dependencies {
compile 'com.android.support:support-v4:24.0.0-alpha1'
compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
compile 'com.android.support:design:24.0.0-alpha1'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-analytics:9.0.0'
compile 'com.google.firebase:firebase-crash:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.firebase:firebase-config:9.0.0'
compile 'com.google.firebase:firebase-invites:9.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
I also use:
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
FirebaseMessaging.getInstance().subscribeToTopic("news");
Log.d(TAG, "Subscribed to news topic");
I added all dependencies that I'll need, but I'm adding one by one and testing one by one, and Notifications works, Analytics: no idea, it takes about 24 hours to update, so until it does, I don't know if is working...
So, the thing is how can I enable it?
NOTE: I have all of the dependencies added including the crash and core ones, also the plugin and the classpath
Thank you in advanced.
Please note the following:
After adding the SDK you can try using:
FirebaseCrash.report(new Exception("My first Android non-fatal error"));
Errors take up to 20 minutes to show up in the Crash Reporting console. Check back to see your report there.
(It may seem obvious but) make sure you have:INTERNET and ACCESS_NETWORK_STATE permission.
Crash reporting was not working for me too after correctly setting it up in my App. To fix this I visited my developer console, API Manager, and enabled the "Mobile Crash and Performance Reporting API". To find out exactly where you need to do this follow the steps on this page.
If you follow the steps in the link above, the logcat that has the text "E/FirebaseCrashSenderServiceImpl: Error sending crash report" gives you a URL to where you must go in the console to enable crash reporting.
The FirebaseCrash is deprecated. The FirebaseCrashlytics.getInstance() should be used instead:
FirebaseCrashlytics.getInstance().log(message)
FirebaseCrashlytics.getInstance().recordException(throwable)
Source: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#add-logs
Add following code:
In Project-level build.gradle (/build.gradle):
buildscript {
dependencies {
// Add this line
classpath 'com.google.gms:google-services:3.0.0'
}
}
In App-level build.gradle (//build.gradle):
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
//Add following in In App-level build.gradle
compile 'com.google.firebase:firebase-crash:9.0.0'
Now sync your project,
Use following code in your activity to throw exception:
FirebaseCrash.report(new Exception("App Name : My first Android non-fatal error"));
check android crash reporting tutorial using firebase for complete guidance.
I had the same issue. Turns out I was missing dependency in my project gradle file. Try adding this. It should help.
buildscript {
repositories {
jcenter()
// ...
}
dependencies {
// ...
classpath 'com.google.firebase:firebase-plugins:1.0.5'
}
}
You should allow some time to show up. Even though the documentation says the errors will show up within 5 minutes, it can take up to 15-20 minutes. Also, you have to change your old modules to AndroidX by migrating it if you use native development. Finally, make sure that all the tools and plugins are added in the appropriate Gradle files.

Categories

Resources