Android深入

保留一套分辨率图片

2021-11-19  本文已影响0人  緦菍亭芷

根目录build.gradle

subprojects {
    println("subprojects project.name:"+project.name)
    deleteDrawable(project)
    deleteMipmap(project)
}

def deleteDrawable(Project project){
    println("deleteDrawable project.name="+project.name)
    File resFile =new  File(project.rootDir,project.name+File.separator +"src"+File.separator+"main"+File.separator+"res")
    List<File> list  = new File(resFile,"mipmap-xxhdpi").listFiles()
    long size =0
    long count =0
    String[] deleteNames = ["drawable-hdpi","drawable-mdpi","drawable-xhdpi","drawable-xxxhdpi"]
    for(File f:list){
        String name =  f.name
        for(String str:deleteNames){
            File dFile =  new File(resFile,str +File.separator +name)
            if(dFile.exists()){
                println("deleteDrawable hdpi name="+dFile.getAbsolutePath())
                size += dFile.size()
                count++
                dFile.delete()
            }
        }
    }

    println("deleteDrawable size="+size)
    println("deleteDrawable count="+count)
}

def deleteMipmap(Project project){
    println("deleteMipmap project.name="+project.name)
    println("deleteMipmap project.rootDir="+project.rootDir)
    File resFile =new  File(project.rootDir,project.name+File.separator +"src"+File.separator+"main"+File.separator+"res")
    List<File> list  = new File(resFile,"mipmap-xxhdpi").listFiles()
    long size =0
    long count =0
    String[] deleteNames = ["mipmap-hdpi","mipmap-mdpi","mipmap-xhdpi","mipmap-xxxhdpi"]
    for(File f:list){
        String name =  f.name
        for(String str:deleteNames){
            File dFile =  new File(resFile,str +File.separator +name)
            if(dFile.exists()){
                println("deleteMipmap hdpi name="+dFile.getAbsolutePath())
                size += dFile.size()
                count++
                dFile.delete()
            }
        }
    }

    println("deleteMipmap size="+size)
    println("deleteMipmap count="+count)
}

上一篇 下一篇

猜你喜欢

热点阅读