gpt4 book ai didi

java - 应用程序在 KitKat 上崩溃

转载 作者:行者123 更新时间:2023-11-29 07:38:20 27 4
gpt4 key购买 nike

我已经在较新的设备上测试了该应用程序,但在较旧的手机上我遇到了崩溃,我不明白:

  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 会失败?关于如何解决这个问题的任何线索?


更新我的应用程序

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);
}

}

最佳答案

问题出在multidex; Lollipop 处理它的方式与 KitKat 不同。如果我做对了,在 KitKat 中,系统无法在一个 dex 文件中找到声明的类,而这些类位于另一个文件中,因此它崩溃了。重要的是,在 build.gradle 中添加 multiDexEnabled true 时,您还必须在 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/

关于java - 应用程序在 KitKat 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016053/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com