Resource not getting set from different app flavor
Asked Answered
S

2

0

https://drive.google.com/file/d/1cIoD5Uw5Jkut--qsJUX_hYBx13gbFNM2/view

See in above video

I have an app with 2 different flavors. I have added different app icons and some different images that is to be replaced. Icons , background images work fine for the other flavor but one image is not picked up from resources, it shows the default image only.

gradle:

productFlavors {
    fibodo {
        applicationId "com.fibodo.consumer"
        versionCode 1
        versionName "4.0.16"
    }

    jdsports {
        applicationId "com.fibodo.jdsports"
        versionCode 1
        versionName "1.0.0"
    }
}

Here are the screenshots in which its clear that preview is coming fine but when running the app it do not show respective logo

fibodo debug

jdDebug

jd screenshot

fibodo screenshot

Sorrell answered 28/11, 2018 at 12:48 Comment(9)
please don't link to screenshots or videos. Just add your code here, you're more likely to get help that way.Whittaker
have you set that image resource in java code too?Soapwort
@fatemehfallahiarezoudar noSorrell
done this by adding condition in java code. But I want it to be done only from xml. is it possible? Please helpSorrell
@Sorrell have you had your resources in all resolutions(hdpi,mdpi,xhdpi,...)?Soapwort
For both flavor Resources are in xxhdpiSorrell
do you have any resources in src/main/res folder?Soapwort
Yes. resource which is shown for both builds is there in main/resSorrell
ok I will prepare your answer with photos :)Soapwort
S
1

when you are using flavors you need to have flavors resoursec in separate folders, for axample if you have these two flavors :

productFlavors {
    fibodo {
        applicationId "com.fibodo.consumer"
        versionCode 1
        versionName "4.0.16"
    }

    jdsports {
        applicationId "com.fibodo.jdsports"
        versionCode 1
        versionName "1.0.0"
    }
}

you should have these folders :

src folder

add your flavor resources in their own folder and remove those resources from your main/res folder.

enter image description here

At this position every flavor first look at their res folders to find resources and if they couldn't find any, they will look at main/res folder, so if you put resources in separated folders they will not get mixed.

Soapwort answered 1/12, 2018 at 6:20 Comment(1)
Thanks for the answer I will definitely trySorrell
E
0

My guess is, you are providing resources it needs for preview device selected in android studio but somehow missing resources for your testing device.

Say your preview device is xhdpi and emulator is xxhdpi, you are only providing resource for xhdpi so it is only working on preview but not in emulator.

There must have been this scenario or something similar, the device is not finding the exact resource it needs, so it is using the default resource!

Eltonelucidate answered 1/12, 2018 at 6:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.