我在较新的设备上测试了该应用程序,但在较旧的手机上我遇到了一个我不明白的崩溃:
E/GMPM: getGoogleAppId failed with status: 10
Uploading is not possible. App measurement disabled
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0xa4d35b20)
FATAL EXCEPTION: main
Process: md.darwin.catalog, PID: 1271
java.lang.NoClassDefFoundError: md.darwin.catalog.utils.AnalyticsTrackers$1
at md.darwin.catalog.utils.AnalyticsTrackers.get(AnalyticsTrackers.java:64)
at md.darwin.catalog.utils.MyApplication.onCreate(MyApplication.java:27)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
我认为它可能与Google Analytics有关,但为什么getGoogleAppId
会失败?关于如何解决这个问题的任何线索?
更新
MyApplication
public class MyApplication extends Application {
public static final String TAG = MyApplication.class
.getSimpleName();
private static MyApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
AnalyticsTrackers.initialize(this);
AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
}
public static synchronized MyApplication getInstance() {
return mInstance;
}
public synchronized Tracker getGoogleAnalyticsTracker() {
AnalyticsTrackers analyticsTrackers = AnalyticsTrackers.getInstance();
return analyticsTrackers.get(AnalyticsTrackers.Target.APP);
}
// and the other methods related to GA
这是AnalyticsTrackers
// AnalyticsTrackers
public final class AnalyticsTrackers {
public enum Target {
APP
}
private static AnalyticsTrackers sInstance;
public static synchronized void initialize(Context context) {
if (sInstance != null) {
throw new IllegalStateException("Extra call to initialize analytics trackers");
}
sInstance = new AnalyticsTrackers(context);
}
public static synchronized AnalyticsTrackers getInstance() {
if (sInstance == null) {
throw new IllegalStateException("Call initialize() before getInstance()");
}
return sInstance;
}
private final Map<Target, Tracker> mTrackers = new HashMap<Target, Tracker>();
private final Context mContext;
/**
* Don't instantiate directly - use {@link #getInstance()} instead.
*/
private AnalyticsTrackers(Context context) {
mContext = context.getApplicationContext();
}
public synchronized Tracker get(Target target) {
if (!mTrackers.containsKey(target)) {
Tracker tracker;
switch (target) {
case APP:
tracker = GoogleAnalytics.getInstance(mContext).newTracker(R.xml.app_tracker);
break;
default:
throw new IllegalArgumentException("Unhandled analytics target " + target);
}
mTrackers.put(target, tracker);
}
return mTrackers.get(target);
}
}
答案 0 :(得分:5)
问题在于multidex
; Lollipop以与KitKat不同的方式处理它。如果我做对了,在KitKat中,系统无法在一个dex文件中找到声明的类,这些文件位于另一个文件中,因此它会崩溃。在multiDexEnabled true
中添加build.gradle
时,您还必须在Application类中设置multidex:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
或者如果您没有Application类,请创建它,然后设置multidex。
http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/