Android studio-无法解析符号R

发布时间: 2016/9/26 1:00:55
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我已经添加了 XML 文件 app_tracker.xmlres\xml 目录,但是它似乎 Android studio找不到它。

我已经重建并同步 Gradle 多次,但它不工作。 我怎么解决的?

import android.app.Application;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import android.R;
import android.R.xml;
import java.util.HashMap;

/**
 * Created by David on 12-Mar-16.
 */
public class MyApplication extends Application
{
    // The following line should be changed to include the correct property id.
    private static final String PROPERTY_ID = "UA-75038910-1";

    //Logging TAG
    private static final String TAG = "WiggleTasks";

    public static int GENERAL_TRACKER = 0;

    public enum TrackerName {
        APP_TRACKER, // Tracker used only in this app.
        GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
        ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
    }

    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

    public MyApplication() {
        super();
    }

    synchronized Tracker getTracker(TrackerName trackerId)
    {
        if (!mTrackers.containsKey(trackerId))
        {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = null;
            if(trackerId == TrackerName.APP_TRACKER)
            {
                t = analytics.newTracker(R.xml.app_tracker);
            }
            else if(trackerId == TrackerName.GLOBAL_TRACKER)
            {
                t = analytics.newTracker(PROPERTY_ID);
            }

            mTrackers.put(trackerId, t);
        }
        return mTrackers.get(trackerId);
    }
}

另一个问题了。我突然收到下面的错误︰

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class

原因是什么?

Gradle 文件

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'me.dm7.barcodescanner:zxing:1.8.4'
    compile 'com.parse:parse-android:1.+'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.google.android.gms:play-services-appindexing:8.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.google.gms:google-services:2.0.0-alpha6'
}

解决方法 1:

请确保您拥有的文件 main\res\xml\app_tracker.xml 安装正确且没有任何错误。

删除这些行,因为他们是为 Android SDK 资源值,不是您的应用程序。

import android.R;
import android.R.xml;

然后尝试清理并重新生成。

官方微信
官方QQ群
31647020