简体   繁体   中英

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.

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.

隐藏的 .gradle 文件夹在哪里

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM