0

I have a custom library I am using inside a client app as a dependency. The client app has a version code and name such that :

versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"

Now the challenge is, i can easily retrieve it within the client app, but I want to be able to retrieve it into the library /dependency aswell to pass on to the server. Anyone has any idea how to go about this?

  • Does this client app use the custom library as a dependency? If so, then you can get the versionCode with this: https://stackoverflow.com/questions/4616095/how-to-get-the-build-version-number-of-your-android-application – Code-Apprentice Sep 20 '18 at 20:53
  • 1
    Possible duplicate of [How to get the build/version number of your Android application?](https://stackoverflow.com/questions/4616095/how-to-get-the-build-version-number-of-your-android-application) – Code-Apprentice Sep 20 '18 at 20:53
  • it does use the custom library as a dependency. However, the challenge is getting the app version number from the client app into the library , not the other way round. –  Sep 20 '18 at 20:55

1 Answers1

0

The problem is you don't have access to client app resources and variables from a library until you declare the app as a dependency for the library which is not possible.

My suggestion is to use a shared module between the client app and the library (add it as a dependency for both) and store your required resources there to read and send to server.

You can also use a Gradle variable to store your app version and then use it in each module build.gradle file in order to declare it as a BuildConfig field and use it as a constant across the java classes. more info on how to declare a Gradle BuildConfig field here.

Sdghasemi
  • 5,370
  • 1
  • 34
  • 42
  • is there any easier way of doing this? since the dependency is already inside the app once its launched, can it retrieve it some other way –  Sep 20 '18 at 21:12
  • I had the same problem and I'm afraid not, there's no way you can access any resources of a module until you announce it as dependency :( but for the Gradle variable declaration I mentioned have a look at https://stackoverflow.com/a/30770088/4399414 and try it out. Hope it helps you. – Sdghasemi Sep 20 '18 at 21:21