You're right Croc, I made a mistake in problem's description - it should be 
"freeFroyoCompile". However, I wrote it correctly in my gradle script.

Thank you Xavier, it almost work for me. Your example was not compiling, 
but I did my best to use your idea.

The code is below. Now I can compile for Froyo, but not for Gingerbread 
because resources from dependency are not accessible:
".../build/manifests/freegingerbread/debug/AndroidManifest.xml:40: error: 
Error: No resource found that matches the given name (at 'value' with value 
'@integer/google_play_services_version')."

When I run froyo version compiled with this script, admob jar seems not to 
be attached:
"E/dalvikvm﹕ Could not find class 'com.google.ads.AdView', referenced from 
method pl.aambitny.spellscontainer.view.common.AdUtils.reloadAd"

task fixDependencies << {
    def freeFlavor = android.productFlavors.free;
    def froyoFlavor = android.productFlavors.froyo;
    def gingerbreadFlavor = android.productFlavors.gingerbread;

    android.applicationVariants.all { variant ->
        def flavors = variant.productFlavors;
        if (flavors.contains(freeFlavor) && flavors.contains(froyoFlavor)) {
            variant.javaCompile.classpath += 
configurations.freeFroyoCompile;
        } else if (flavors.contains(freeFlavor) && 
flavors.contains(gingerbreadFlavor)) {
            variant.javaCompile.classpath += 
configurations.freeGingerbreadCompile
        }
    }
}

tasks.whenTaskAdded { theTask ->
    if (theTask.name.startsWith("compile")) {
        theTask.dependsOn "fixDependencies"
    }
}

On Thursday, March 27, 2014 4:34:43 PM UTC+1, Xavier Ducrohet wrote:
>
> It's not directly possible right now due to some issue in how we setup the 
> tasks and variants. This should be possible in the long term though.
>
> Right now you could do something like this:
>
> configurations {
>   freeFroyoCompile
> }
>
> dependencies {
>   freeFroyoCompile ...
> }
>
> android.applicationVariants.all { variant ->
>   if (variant is freeFroyo) {
>     variant.javaCompile.classpath += freeFroyoCompile.files
>   }
> }
>
>
>
>
> On Thu, Mar 27, 2014 at 7:37 AM, Croc <[email protected] <javascript:>>wrote:
>
>> "froyoFreeCompile" is probably not recognized because I think you used 
>> the wrong order of flavors. The order should be the same as was declared in 
>> "flavorGroups", so it should actually be "freeFroyoCompile".
>>
>>
>> On Saturday, March 22, 2014 8:06:49 PM UTC+1, Paweł Stankowski wrote:
>>>
>>> I have two flavor groups: "api" (froyo and gingerbread flavors) and 
>>> "variant" (free and pro flavors).
>>>
>>> How to add dependency only to one build variant, ie only for froyo-free 
>>> version? 'froyoFreeCompile' is not recognized by gradle (both freeCompile 
>>> and froyoCompile are working as expected). If this is not possible 
>>> directly, may I add such dependency using customized task?
>>>
>>> My build.gradle:
>>>
>>> ...
>>>     flavorGroups "variant", "api"
>>>
>>>     productFlavors {
>>>         free {
>>>             flavorGroup "variant"
>>>             packageName "..."
>>>         }
>>>         pro {
>>>             flavorGroup "variant"
>>>             packageName "..."
>>>         }
>>>
>>>         froyo {
>>>             flavorGroup "api"
>>>             minSdkVersion 8
>>>         }
>>>         gingerbread {
>>>             flavorGroup "api"
>>>             minSdkVersion 9
>>>         }
>>>     }
>>> }
>>>
>>> dependencies {
>>>     freeFroyoCompile files(getSdkDir() + '/extras/google/admob_ads_sdk/
>>> GoogleAdMobAdsSdk-6.4.1.jar')
>>>     freeGingerbreadCompile 'com.google.android.gms:play-services:+'
>>> }
>>>
>>> ...
>>>
>>  -- 
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Xavier Ducrohet
> Android SDK Tech Lead
> Google Inc.
> http://developer.android.com | http://tools.android.com
>
> Please do not send me questions directly. Thanks! 
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to