Search code examples
javaandroidcachingassets

Android Studio - How to clear assets folder cache?


I used Android Studio to manage my Android code. In the project structure, I created the assets folder which saves some emoticons in different folders.

asset folder

But somehow, when I switch between 2 branches which using different folders and emoticons, and use these codes as below to load all images in those folders:

public static boolean initialize(Context context) {

    if(tapEmoticonNameMap!=null)
        return true;

    tapEmoticonNameMap = new HashMap<>();
    try {
        for(String tabDir : tabStringList) {
            String[] list = context.getAssets().list(tabDir);
            if (list.length > 0) {
                ArrayList<String> pngList = new ArrayList<>();
                for(String name : list) {
                    if(name.endsWith(".png")) {
                        pngList.add(name);
                    }
                }
                tapEmoticonNameMap.put(tabDir, pngList);
            }
        }

    } catch (IOException e) {
        return false;
    }
    return true;
}

In fact, It loaded not only every actual images in those folders but also including ones in the previous branch. Any suggestions to solve this problem? How can I remove the cache folder in this case? Any help would be appreciated.


Solution

  • After taking a half-day to struggle with a bunch of ways:

    • clean/rebuild project so many times
    • following the way how to clear cache from this link How to clear gradle cache?
    • importing project again
    • restarting the computer and building again and again

    But the problem is still there. Eventually, I found how to deal with this terrible problem.

    where hidden .gradle folder is

    The solution is we should REMOVE hidden .gradle folder in project folder.

    I hope this helps, especially for those who are facing the same problem like me.