Re: Does gradle android plugin support runtime dependencies

7,630 views
Skip to first unread message

Xavier Ducrohet

unread,
Jun 18, 2013, 11:21:07 AM6/18/13
to adt...@googlegroups.com
'runtime' is not a valid dependency configuration. 'apk' is the configuration to add dependency only for packaging but not compiling.


On Mon, Jun 3, 2013 at 8:06 PM, <huan.zh...@gmail.com> wrote:
Hi,
I'm using android studio, but i'm facing a problem that gradle android plugin seems not supporting runtime dependencies, 
which BTW is not a problem when i was using Eclipse to develop or use Android.mk to compile with source code build system.

i'm trying to do this.

buildscript {
   .......
}
apply plugin: 'android'
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    runtime file('lib/pluginapi.jar')
}
android {
   ......
}

when i compile with 'gradle build', i got below error:

A problem occurred evaluating root project 'XXXXX'.
> Could not find method runtime() for arguments [C:\Work\Android\workspace\XXXXX\lib\pluginapi.jar] on root project 'XXXXX'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I don't think runtime dependency is meaningless for Android, sometimes, we need to use this feature.
Thanks much for your feedback!

--
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/groups/opt_out.
 
 



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Eason

unread,
Jul 18, 2013, 10:39:42 PM7/18/13
to adt...@googlegroups.com

Xavier Ducrohet <xav <at> android.com> writes:

>
>
> 'runtime' is not a valid dependency configuration. 'apk' is the
configuration to add dependency only for packaging but not compiling.
>
>
>
> On Mon, Jun 3, 2013 at 8:06 PM, <huan.zheng.ray <at> gmail.com> wrote:
>
> Hi,I'm using android studio, but i'm facing a problem that gradle android
plugin seems not supporting runtime dependencies, 
> which BTW is not a problem when i was using Eclipse to develop or use
Android.mk to compile with source code build system.
>
>
> i'm trying to do this.
>
>
>
> buildscript {   .......}apply plugin: 'android'dependencies {    compile
fileTree(dir: 'libs', include: '*.jar')    runtime
file('lib/pluginapi.jar')}android {   ......}
>
> when i compile with 'gradle build', i got below error:
>
>
>
>
> A problem occurred evaluating root project 'XXXXX'.> Could not find method
runtime() for arguments [C:\Work\Android\workspace\XXXXX\lib\pluginapi.jar]
on root project 'XXXXX'.* Try:Run with --stacktrace option to get the stack
trace. Run with --info or --debug option to get more log output.
>
>
>
> I don't think runtime dependency is meaningless for Android, sometimes, we
need to use this feature.
>
> Thanks much for your feedback!
>
>
>
>

Hi all,

I'm new to Gradle, I don't know how to find the entrance to propose a new
problem, thus, I would like to ask one question about plugin-dependencies
like this.

Could someone give me some directions? Thanks a lot

My question is:

(1)What the dependency which "android" plugin have?

It's because I've had many times "try-and-error" to use runtime
dependency configuration in "android" plugin, and finally find the "runtime"
is only supported in "java" plugin.
Is there any document to find which dependency configuration is supported?

Thanks a lot for your great help.



Xavier Ducrohet

unread,
Jul 19, 2013, 12:13:47 AM7/19/13
to adt...@googlegroups.com


--
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/groups/opt_out.


Eason

unread,
Jul 19, 2013, 7:00:56 AM7/19/13
to adt...@googlegroups.com
> Question
Hi Xavier Ducrohet,

Thanks a lot for your response, but I'm still confused. Could you please
help me
again? Thanks a lot. My question is, for example:

If I want to build apk without referencing one jar(ex:XXX.jar), I can't use
compile" dependency because the XXX.jar will also be packaged into apk if
using "compile files('XXX.jar')".

I've tried to use "runtime" dependency, but this will get the error called
"Could not find method runtime() for arguments"

Finally, I know "android" plugin doesn't support "runtime" dependency.

After searching from google, I should use my own dependency, called "provided".
Then my build.gradle will be:

configurations {
provided
}

dependencies {
provided files('libs/jarSample.jar')
}

android.applicationVariants.each { variant ->
variant.javaCompile.classpath += configurations.provided
}

After building, I will get the apk without jarSample.jar be packaged.


Finally, my question is:
(1)How do I know which dependency is supported by "android" plugin?
(2)I don't really know what "variant.javaCompile.classpath" stands for.

Could you please help me? Thanks a lot.

>Xavier Ducrohet <xav <at> android.com> writes:
>
>
>
>
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Dependencies-Android-Libraries-and-Multi-project-setup
>
>
> On Thu, Jul 18, 2013 at 7:39 PM, Eason <lovewen1012 <at> gmail.com> wrote:
>
>
> Xavier Ducrohet <xav <at> android.com> writes:
> >
> >
> > 'runtime' is not a valid dependency configuration. 'apk' is the
> configuration to add dependency only for packaging but not compiling.
> >
> >
> >
> > On Mon, Jun 3, 2013 at 8:06 PM,  <huan.zheng.ray <at> gmail.com> wrote:
> >
> > Hi,I'm using android studio, but i'm facing a problem that gradle
androidplugin seems not supporting runtime dependencies, 
> > which BTW is not a problem when i was using Eclipse to develop or use
> Android.mk to compile with source code build system.
> >
> >
> > i'm trying to do this.
> >
> >
> >
> > buildscript {   .......}apply plugin: 'android'dependencies {    compile
> fileTree(dir: 'libs', include: '*.jar')    runtime
> file('lib/pluginapi.jar')}android {   ......}
> >
> > when i compile with 'gradle build', i got below error:
> >
> >
> >
> >
> > A problem occurred evaluating root project 'XXXXX'.> Could not find method
> runtime() for arguments [C:\Work\Android\workspace\XXXXX\lib\pluginapi.jar]
> on root project 'XXXXX'.* Try:Run with --stacktrace option to get the
stacktrace. Run with --info or --debug option to get more log output.
> >
> >
> >
> > I don't think runtime dependency is meaningless for Android, sometimes, we
> need to use this feature.
> >
> > Thanks much for your feedback!
> >
> >
> >
> >
> Hi all,
> I'm new to Gradle, I don't know how to find the entrance to propose a new
> problem, thus, I would like to ask one question about plugin-dependencies
> like this.
> Could someone give me some directions? Thanks a lot
> My question is:
> (1)What the dependency which "android" plugin have?
>    It's because I've had many times "try-and-error" to use runtime
> dependency configuration in "android" plugin, and finally find the "runtime"
> is only supported in "java" plugin.
> Is there any document to find which dependency configuration is supported?
> Thanks a lot for your great help.
>
> --
> 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+unsubscribe <at> googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> -- Xavier DucrohetAndroid SDK Tech LeadGoogle
Inc.http://developer.android.com | http://tools.android.comPlease do not

Xavier Ducrohet

unread,
Jul 19, 2013, 12:15:42 PM7/19/13
to adt...@googlegroups.com
I thought the section of the doc I linked you to had the information but it doesn't! sorry about that.

in the Android plugin, The equivalent (sort of) of runtime is called apk. You can do

dependencies {
   apk files('libs/foo.jar')
}

and it'll only get packaged but won't be on the compile classpath.

However it sounds like you want the opposite. It seems you want to have the jar be used for compilation but not for packaging?
In a 'java' project 'runtime' is not what you want.

I think you can do something like this, but I'm not 100% sure.

dependencies {
    compile files('libs/foo.jar')
    apk.exclude files('foo.jar')
}

Again I'm not 100% sure this is going to work. I have to check.

Your current code should work though. as you create a new dependency configuration, add your dependency to it and then manually add it to the compilation classpath. The final packaging will not know about this dependency so it won't get in the apk.


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/groups/opt_out.





--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Andy Lo A Foe

unread,
Aug 16, 2013, 1:51:10 PM8/16/13
to adt...@googlegroups.com
I just ran into the same issue where I needed to exclude the jar for a a device provided implementation (uses-library). The following gradle config snippet worked for me:

configurations {
    provided
}

android.applicationVariants.all {
    variant -> variant.javaCompile.classpath += configurations.provided
}

dependencies {
    provided files('libs/samsung_ble_sdk_200.jar')
}

Last comment in https://code.google.com/p/android/issues/detail?id=55764 helped i.e. use ".all" instead of ".each" for latest gradle release.

Cheers,
Andy

Scott Culverhouse

unread,
Jan 3, 2014, 5:48:21 AM1/3/14
to adt...@googlegroups.com
The below works with the latest buildtools (19.0.1) and gradle plugin (0.7.2) in terminal however in AS it shows "Cannot resolve symbol" for the jar which is "provided".

Any ideas on how to exclude the certain classes from the dex. This is for the xposed framework where the jar is already on the device.

Michael Barany

unread,
Jan 3, 2014, 1:11:47 PM1/3/14
to adt...@googlegroups.com
Try plugin 0.7.3, there was a bug in 0.7.2 that limited it to Java 1.6

Scott Culverhouse

unread,
Jan 3, 2014, 1:27:02 PM1/3/14
to adt...@googlegroups.com
It transpires I was using 0.7.3 (ie 0.7.+), I've forced it to 0.7.3 and the same result in AS (Android Studio 0.4.0).

BTW it compiles OK within AS it's just the code completion and error highlighting.

Xavier Ducrohet

unread,
Jan 3, 2014, 2:06:02 PM1/3/14
to adt...@googlegroups.com
This is normal as the dependencies given to the IDE are built from the actual dependency graph.

you are manually editing the classpath of the compile task which bypasses the model. There's no API to add extra dependencies to the model when you do this.


--
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/groups/opt_out.

Scott Culverhouse

unread,
Jan 3, 2014, 2:37:24 PM1/3/14
to adt...@googlegroups.com
Thanks for the reply Xavier.

Ok looking from another angle within the Java/Android plugin gradle plugins is it possible to remove classes from the final dex?

Or would I be best add a postDex task which removes them somehow or a postPackage which baksmali/smali/rezips apk?

Daniel Lew

unread,
Jan 28, 2014, 4:04:58 PM1/28/14
to adt...@googlegroups.com
I wanted to revive this thread because I'm running into the same issues here.  In the same way that android.jar is not included in APKs, there's some Amazon jars that are not included either.

It's okay to have this workaround but it makes working in AS somewhat of a pain.  I'm curious if there's ever going to be plans to improve support for this, or if we should try out Scott's suggestion of removing JARs postDex or something...

-Daniel

Xavier Ducrohet

unread,
Jan 28, 2014, 5:47:37 PM1/28/14
to adt...@googlegroups.com
With Gradle 0.8 there's a new provided scope that allows you to add compile-only dependencies (ie they don't get packaged in the apk).

Daniel Lew

unread,
Jan 29, 2014, 9:15:01 AM1/29/14
to adt...@googlegroups.com
Hah, I'm dumb.  I should've read those release notes closer.  Thanks so much!

-Daniel


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/WIjtHjgoGwA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Вадим П

unread,
Feb 13, 2014, 11:54:04 PM2/13/14
to adt...@googlegroups.com
Do anybody have successful example of using "provided" with android-library?
In my case provided files('somejar1.jar', 'somejar2.jar') and compile files('somejar1.jar', 'somejar2.jar') are generating equal APKs

среда, 29 января 2014 г., 20:15:01 UTC+6 пользователь Daniel Lew написал:

Olexandr Tereshchuk

unread,
Feb 28, 2014, 7:04:09 AM2/28/14
to adt...@googlegroups.com
same for me - provided dependencies do not packaged into jar but do packaged into aar and apk

Пʼятниця, 14 лютого 2014 р. 06:54:04 UTC+2 користувач Вадим П написав:

Xavier Ducrohet

unread,
Feb 28, 2014, 11:55:41 AM2/28/14
to adt...@googlegroups.com
This obviously should not be the case. I'll double check.

Vitaliy Istomov

unread,
Mar 24, 2014, 6:42:35 AM3/24/14
to adt...@googlegroups.com
Hi guys,

I am using gradle 1.11 and "android-library" plugin 0.9.0 and experiencing the same issue with packaging "provided files('libs/<libname>.jar')" entries to the .aar library: there "provided" jar files are in the resulting aar library.

I would really appreciate the fix for this or a temporary workaround (I have not succeeded in finding one so far). Thanks in advance!

-Vitaliy

Richard Lee

unread,
Apr 24, 2014, 6:29:16 PM4/24/14
to adt...@googlegroups.com
Hi Vitaliy,

You don't need to custom "provided" configurations in the 0.9 plugin, just add this to your build.gradle:

android.libraryVariants.all { variant ->
    variant.packageLibrary.exclude( 'libs/somejars.jar' )
}

Enjoy!

Best regards,
Richard Lee

Mike T

unread,
Jun 11, 2014, 4:19:57 AM6/11/14
to adt...@googlegroups.com
Thanks Richard for pointing me in the right direction. Your stackoverflow post is a little different from this reply. Took me a while to figure that out ;).

However I think, there is an issue in the gradle build system nonetheless, since this "provided configuration" - approach did not work for libraries, only your exclude() approach did. Not sure if this is a coincidence. Maybe I did not clean the project properly, but in the end i got it working.

br
Mike

Vitaliy Istomov

unread,
Jul 7, 2014, 10:31:19 AM7/7/14
to adt...@googlegroups.com
Hi Richard,

Looks like I have missed the reply when it arrived and noticed it just now. But, anyway, the issue was still there and it helped me, so thank you!

Vitaliy

Richard Lee

unread,
Jul 7, 2014, 2:09:18 PM7/7/14
to adt...@googlegroups.com
:-), glad to know it helps.


For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages