我在app_tracker.xml
目录下添加了一个XML文件res\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'
}
答案 0 :(得分:1)
确保正确设置文件main\res\xml\app_tracker.xml
,没有任何错误。
删除这些行是因为它们适用于Android SDK资源值,而不是您的应用。
import android.R;
import android.R.xml;
然后尝试清理并重建。