17

How can I get the application ID from the application using my library using gradle?

Or any way to put it inside a xml file.

kaneda
  • 5,981
  • 8
  • 48
  • 73
  • 8
    Call `getPackageName()` on a `Context` supplied to your library. – CommonsWare Oct 02 '15 at 14:20
  • I need to set it in my res/xml/authenticator.xml -> accountType. So I think I can't get it this way, unless I could find a way to configure the authenticator at runtime – kaneda Oct 02 '15 at 14:22
  • I don't know of a way for you to modify a XML resource at compile time like that, other than by some custom Gradle task. – CommonsWare Oct 02 '15 at 14:23
  • That's what I am trying to do now using Gradle. Is there a way to get the application Id from the app using my library? – kaneda Oct 02 '15 at 14:27
  • Sorry, I meant that the custom Gradle task would be in the app, and the app would have its own `res/xml/authenticator.xml`, overriding anything you ship with your library. The application ID is only known at the time of compiling the app. – CommonsWare Oct 02 '15 at 14:29

2 Answers2

6

You want to get Your App id that defined in gradle then it is

BuildConfig.APPLICATION_ID 

or You can get it

Context.getPackageName()
Chanaka Weerasinghe
  • 5,404
  • 2
  • 26
  • 39
4

Only Android application project can contain the applicationId property in app build.gradle file.

Android Library project must not contain the applicationId property in app build.gradle file. so there is no way to retrieve the application id from the library.

Logo
  • 1,366
  • 2
  • 11
  • 16