0

In this page: https://developer.android.com/studio/projects/android-library.html#Considerations

It states that:

You can develop a library module that depends on an external library. (for example, the Maps external library). In this case, the dependent app must build against a target that includes the external library (for example, the Google APIs Add-On). Note also that both the library module and the dependent app must declare the external library in their manifest files, in a element.


So I tried to do what the paragraph says above.

1- I created a module that has this in its gradle:

compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-ui:3.0.0'

2- and I added this in my manifest.xml

<uses-library
android:name="com.twitter.sdk"
android:required="true"/>

3- I imported my .aar file to my main app.

4- I added the same code into my main app manifest.xml

<uses-library
android:name="com.twitter.sdk"
android:required="true"/>

But of-course it shows an error:

enter image description here

Suhaib
  • 2,031
  • 3
  • 24
  • 36
  • check if you have app installed on your device with same package name if yes uninstall it first. Mostly happens due to having play store app installed in device and we try to install app through Android studio. – Nilesh Deokar Jul 27 '17 at 17:36
  • @NileshDeokar, I created a new project with new unique name but I got the same error. – Suhaib Jul 27 '17 at 17:41

1 Answers1

1

Delete <uses-library> from your manifest. It it only for cases where you are trying to use a "library" that is part of a device's firmware. The "Maps" example that they cite is from the long-obsolete Google Maps V1 for Android implementation.

I am not aware of any device manufacturer that has advised its developers to add <uses-library> elements to their manifest for com.twitter.sdk.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for your reply. when I delete it and then my main app calls a class that launches twitter sdk. It will crash with an error that says: `can't find path for class twitter sdk.confi`. – Suhaib Jul 27 '17 at 17:47
  • What is the correct approach if I want to create a module that has twitter sdk or any other libraries found in my modules `gradle` ? – Suhaib Jul 27 '17 at 17:48
  • 1
    @Suhaib: Either add the `compile` lines for the Twitter libraries to both the library module and the app module, or have the app module pull in the library module directly (not via importing some AAR), or publish the AAR as an artifact in a repository and have the app depend upon the AAR from that repository. An AAR on its own has no details regarding its transitive dependencies, just as a JAR on its own has no details regarding its transitive dependencies. – CommonsWare Jul 27 '17 at 17:49
  • thank you, regarding this sentence, `AAR as an artifact in a repository`. Sorry but i'm new. Do you mean upload it to maven/jCenter ? – Suhaib Jul 27 '17 at 17:53
  • @Suhaib: It could be a local repository. However, unless you have 2+ apps that are going to use this library *soon* (i.e., immediately, or in days or weeks), I would recommend simply having the library be a module in the same project as the app, and use `compile project(':libraryname)`) to have the app refer to the library. That is simpler that fussing with a local Maven repository when there is only one app consuming the library. – CommonsWare Jul 27 '17 at 17:57
  • @CommonsWare, I have the library module and I am using it by "implementation project(':xyz') in my app module. and my "xyz" module is dependant on 3rd party library. Do I need to implement those 3rd party libraries to my main app module as well? – Kalpesh Wadekar Sep 07 '20 at 11:51
  • @KalpeshWadekar: "Do I need to implement those 3rd party libraries to my main app module as well?" -- that will depend on how the third-party library is added to `xyz`. If you used `implementation`, then yes, consumers of `xyz` would need to manually add the third-party library. If you used `api`, then Gradle will handle this automatically. If you have additional concerns in this area, I recommend that you ask a separate Stack Overflow question, where you can provide a [mcve] showing the Gradle files fro `xyz` and a module that depends upon `xyz`. – CommonsWare Sep 07 '20 at 11:56
  • @CommonsWare, Yes I have used `implementation` of 3rd party library to `xyz` module and yes I have to `implement` those dependencies in my main `app` module. But I didn't get the reason, why we need to duplicate the dependencies? – Kalpesh Wadekar Sep 08 '20 at 06:45
  • @KalpeshWadekar: `implementation` says "nothing else needs this". That is rarely the case for a dependency in a library module. `api` says "anything that depends on me also needs this". This is the normal case for a library module. See [the Android documentation](https://developer.android.com/studio/build/dependencies#dependency_configurations). The Android Gradle plugin is modeled after the Java library plugin, so you can read more about this in [the Gradle documentation](https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation) as well. – CommonsWare Sep 08 '20 at 11:00