美文网首页Android深入
保留一套分辨率图片

保留一套分辨率图片

作者: 緦菍亭芷 | 来源:发表于2021-11-19 09:51 被阅读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)
}

相关文章

网友评论

    本文标题:保留一套分辨率图片

    本文链接:https://www.haomeiwen.com/subject/voljtrtx.html