“错误:在尝试谷歌分析时找不到符号变量xml”

时间:2022-01-13 15:21:42

I am trying to implement google analytics for one of my android apps. I am totally new for analytics and android app development. I thought of trying the examples given in the google developers site. When trying to compile their code, I am getting the error pointing the analytics application java file, mTracker = analytics.newTracker(R.xml.global_tracker); line, .xml is highlighted. I posted the whole code here.

我正在尝试为我的一个android应用程序实现谷歌分析。我对分析和android应用开发完全陌生。我想尝试谷歌开发人员站点中给出的示例。在试图编译它们的代码时,我得到了指向分析应用程序java文件mTracker = analytics.newTracker(R.xml.global_tracker)的错误;行,. xml是突出显示。我把整个代码都贴在这里了。

This is AnalyticsApplication.java

这是AnalyticsApplication.java

package com.google.samples.quickstart.analytics;

import android.app.Application;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;

public class AnalyticsApplication extends Application {
  private Tracker mTracker;

  synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
      GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
      // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
      mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
  }
}

My Global_tracker.xml file

我的Global_tracker。xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--Replace placeholder ID with your tracking ID-->
    <string name="ga_trackingId">UA-XXXXXXXX-X</string>

    <!--Enable automatic activity tracking-->
    <bool name="ga_autoActivityTracking">true</bool>

    <!--Enable automatic exception tracking-->
    <bool name="ga_reportUncaughtExceptions">true</bool>
</resources>

My manifest file

我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.samples.quickstart.analytics">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:name=".AnalyticsApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

I have already spent two complete days in this issue, and I need your suggestion to go forwards.

这个问题我已经花了整整两天时间,我需要你的建议。

Thanks.

谢谢。

5 个解决方案

#1


16  

You need to create a new folder in your res folder called xml and move your file to that folder. Also make sure you call the layout name correctly because in your question, you wrote Global_tracker.xml instead of global_tracker.xml. This is so important.

您需要在名为xml的res文件夹中创建一个新文件夹,并将文件移动到该文件夹。还要确保正确调用布局名,因为在您的问题中,您编写了Global_tracker。xml而不是global_tracker.xml。这是非常重要的。

Hope that helps.

希望有帮助。

#2


2  

Check if you don't forget to put

检查你是否忘了放

apply plugin: 'com.google.gms.google-services'

应用插件:“com.google.gms.google-services”

in app level build.gradle

在应用程序级别build.gradle

#3


0  

I had the similar issue when was preforming downgrade to lower version from

我也遇到过类似的问题,就是把降级到更低的版本

com.google.gms:google-services:3.0.0

to

com.google.gms:google-services:1.3.1

(Do not ask why(it was an assumption in order to fix CI build script in a hurry))

(不要问为什么(为了快速修复CI构建脚本,这是一个假设))

So, make sure that you did not made downgrade changes

因此,请确保您没有做出降级更改

#4


0  

I also faced the same issue with play service library version 10.2.1 for gcm and google analytics and issue is simply fixed by adding global_tracker.xml as discussed in the @Hussein El Feky Answer but only that fix is not solved my issue also i've added two more lines in strings.xml:

gcm和谷歌分析的play服务库10.2.1版本也遇到了同样的问题,只要添加global_tracker就可以解决这个问题。在@Hussein El Feky的回答中讨论的xml,但是只有这个解决方案没有解决我的问题,我还在strings.xml中添加了两行。

<string name="global_tracker">UA-XXXXXXXX-XX</string>
<string name="gcm_defaultSenderId">PROJECT-NO</string>

#5


-2  

I was facing the similar issue.

我也面临着类似的问题。

Use classpath com.android.tools.build:gradle:1.2.3. That solved my problem.

使用类路径com.android.tools.build:gradle:1.2.3。这解决了我的问题。

#1


16  

You need to create a new folder in your res folder called xml and move your file to that folder. Also make sure you call the layout name correctly because in your question, you wrote Global_tracker.xml instead of global_tracker.xml. This is so important.

您需要在名为xml的res文件夹中创建一个新文件夹,并将文件移动到该文件夹。还要确保正确调用布局名,因为在您的问题中,您编写了Global_tracker。xml而不是global_tracker.xml。这是非常重要的。

Hope that helps.

希望有帮助。

#2


2  

Check if you don't forget to put

检查你是否忘了放

apply plugin: 'com.google.gms.google-services'

应用插件:“com.google.gms.google-services”

in app level build.gradle

在应用程序级别build.gradle

#3


0  

I had the similar issue when was preforming downgrade to lower version from

我也遇到过类似的问题,就是把降级到更低的版本

com.google.gms:google-services:3.0.0

to

com.google.gms:google-services:1.3.1

(Do not ask why(it was an assumption in order to fix CI build script in a hurry))

(不要问为什么(为了快速修复CI构建脚本,这是一个假设))

So, make sure that you did not made downgrade changes

因此,请确保您没有做出降级更改

#4


0  

I also faced the same issue with play service library version 10.2.1 for gcm and google analytics and issue is simply fixed by adding global_tracker.xml as discussed in the @Hussein El Feky Answer but only that fix is not solved my issue also i've added two more lines in strings.xml:

gcm和谷歌分析的play服务库10.2.1版本也遇到了同样的问题,只要添加global_tracker就可以解决这个问题。在@Hussein El Feky的回答中讨论的xml,但是只有这个解决方案没有解决我的问题,我还在strings.xml中添加了两行。

<string name="global_tracker">UA-XXXXXXXX-XX</string>
<string name="gcm_defaultSenderId">PROJECT-NO</string>

#5


-2  

I was facing the similar issue.

我也面临着类似的问题。

Use classpath com.android.tools.build:gradle:1.2.3. That solved my problem.

使用类路径com.android.tools.build:gradle:1.2.3。这解决了我的问题。