解决gradle一直提示更新:Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.

一直显示:Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly...对于有强迫症的我来说忍无可忍,明明没有动gradle文件,却一直显示这个,上Google询问时,看到stackoverflow有个答案,原来是文件修改时间比当前的晚.苦于要改的文件太多,于是搞了个工具类:

  • 批量修改时间

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by hejianfeng on 17/3/16.
 */
public class ModifyAll {
    public static void main(String[] args) throws IOException {
        List folderList = new ArrayList();
        List fileList = new ArrayList();

        File folder = new File("/Users/hejianfeng/AndroidStudioProjects/git");
        FileVO baseFileVO = segregateFiles(folder);
        fileList.addAll(baseFileVO.getFileList());
        folderList.addAll(baseFileVO.getFolderList());

        for (int i = 0; i < folderList.size(); i++) {
            FileVO thisVO = segregateFiles(folderList.get(i));
            fileList.addAll(thisVO.getFileList());
            folderList.addAll(thisVO.getFolderList());
        }

        for (int i = 0; i < fileList.size(); i++) {
            Date dte = new Date();
            long milliSeconds = dte.getTime();
            System.out.println("Setting Time For " + fileList.get(i) + " \nas " + milliSeconds);
            fileList.get(i).setLastModified(milliSeconds);
        }

        for (int i = 0; i < folderList.size(); i++) {
            Date dte2 = new Date();
            long milliSeconds = dte2.getTime();
            folderList.get(i).setLastModified(milliSeconds);
        }
        System.out.println("Succesfully Modified..!!!");


    }

    public static FileVO segregateFiles(File folder) {
        List folderList = new ArrayList();
        List fileList = new ArrayList();

        File[] listOfFiles = folder.listFiles();
        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                fileList.add(listOfFiles[i]);
            } else {
                folderList.add(listOfFiles[i]);
            }
            System.out.println(listOfFiles[i]);
        }
        return new FileVO(fileList, folderList);
    }


    public static class FileVO {
        List fileList = new ArrayList();
        List folderList = new ArrayList();

        public FileVO(List fileList, List folderList) {
            this.fileList = fileList;
            this.folderList = folderList;
        }

        public List getFileList() {
            return fileList;
        }

        public void setFileList(List fileList) {
            this.fileList = fileList;
        }

        public List getFolderList() {
            return folderList;
        }

        public void setFolderList(List folderList) {
            this.folderList = folderList;
        }
    }
}

参考:
http://stackoverflow.com/questions/28634836/gradle-files-have-changed-since-last-project-sync-message-always-shows-up

你可能感兴趣的:(解决gradle一直提示更新:Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.)