difference between dependency with @aar and without it

600 views
Skip to first unread message

Tomáš Procházka

unread,
Feb 19, 2015, 4:45:41 PM2/19/15
to adt...@googlegroups.com
I'm confused. What is difference between

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3@aar'
}

and

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
}

I thinked that if I skip @aar gradle will tray to use jar dependency, but appcompat doesn't have jar type, only aar.
So I'm using @aar, but it doesn't work sometimes, for example here


If I add @arr here it fail 

android-styled-dialogs\library\src\main\java\com\avast\android\dialogs\core\BaseDialogBuilder.java:5: error: package android.support.v4.app does not exist
import android.support.v4.app.DialogFragment;
                             ^
android-styled-dialogs\library\src\main\java\com\avast\android\dialogs\core\BaseDialogBuilder.java:6: error: package android.support.v4.app does not exist
import android.support.v4.app.Fragment;
                             ^
android-styled-dialogs\library\src\main\java\com\avast\android\dialogs\core\BaseDialogBuilder.java:7: error: package android.support.v4.app does not exist
import android.support.v4.app.FragmentManager;

I don't understand why it sometimes works and sometimes not.
I'm asking because of this
I want to force propagate <type>aad</type> to the generated pom.xml



Message has been deleted

Jonathan Steele

unread,
Feb 19, 2015, 8:20:11 PM2/19/15
to adt...@googlegroups.com
first one = use explicit type
2nd one = use default type

I think a future version of Gradle is removing the 2nd types.

Jake Wharton

unread,
Feb 19, 2015, 10:56:15 PM2/19/15
to adt...@googlegroups.com
By appending the artifact packaging, you are telling Gradle's resolver to skip looking at the pom.xml that defines the metadata for the artifact. This metadata includes the default packaging (in this case, aar) and more importantly it also includes information on dependencies which are resolved transitively by default.

In your case, when you incorrectly explicitly include the packaging in the dependency (the "@aar" part), you are not getting AppCompat's dependency on the support-v4 library.

You almost never want to specify explicit packaging.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tomáš Procházka

unread,
Feb 20, 2015, 7:20:48 AM2/20/15
to adt...@googlegroups.com
Thanks. I already understand it.
It looks that Gradle trying to be more smart than user :-)

So this is still issue, because it must work also without @aar

William Ferguson

unread,
Feb 21, 2015, 12:55:13 AM2/21/15
to adt...@googlegroups.com
Jake, 

the problem many of us have is that the POM for AppCompat declares this dependency:

    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-v4</artifactId>
      <version>21.0.3</version>
      <scope>compile</scope>
    </dependency>

which doesn't exist as by POM convention it has type of 'jar', but support-v4:21.0.3 ships as an aar. So other build tools such as Maven cannot resolve AppCompat's dependencies.


William
Reply all
Reply to author
Forward
0 new messages