1

我有一个 android 应用程序,我在内部依赖几个库。现在我正在尝试记录在单个组件级别(这意味着单个库级别)发生的崩溃,以便帮助我分析导致崩溃的组件。

public class MyApplication extends Application implements Thread.UncaughtExceptionHandler {

    public static final String TAG = "myapplication";

    public static MyApplication applicationInstance;

    public MyApplication() {
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public Context getApplicationContext() {
        return super.getApplicationContext();
    }

    public static MyApplication getInstance() {
        return applicationInstance;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }


    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Log.i(TAG, "Inside uncaught exception..." + Thread.currentThread().getId());
        //getPackageName() here returns the name of the application instead of the dependent library's one. 
    }
}

有什么方法可以获取在他们的 android 清单中添加的库的包名称?

4

1 回答 1

2

并不真地。库没有应用程序 ID。清单中的package属性仅用于代码生成,仅此而已。

如果你碰巧有一个库中的对象,你可以得到与那个类相关联的 Java 包,并可能从那里推断出你所指的是哪个库。

于 2019-11-24T14:58:03.607 回答