1

I've an android application where I depend on few libraries internally. Now I'm trying to log the crash happening at individual component level (which means individual library level) so that it would help me in analyzing which component is causing the crash.

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. 
    }
}

Is there any way available to get the package name of the library added in their android manifest?

Tom Taylor
  • 3,344
  • 2
  • 38
  • 63

1 Answers1

3

Not really. Libraries do not have application IDs. The package attribute in the manifest is just used for code generation, nothing more.

If you happen to have an object from the library, you can get the Java package associated with that class, and perhaps from there infer which library it is that you are referring to.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yeah, I thought of exactly the same way then I came into another problem where there are n number of java packages within the same library - and it's hard for me to group them under the same package - without maintaining a whitelist of packages which I consume. – Tom Taylor Nov 24 '19 at 15:00