Code Monkey home page Code Monkey logo

Comments (6)

wl386123298 avatar wl386123298 commented on September 28, 2024

怀疑是缓存引起,但是uniapp android sdk提供的api 简直少的可怜

from uni-app.

wl386123298 avatar wl386123298 commented on September 28, 2024

贴一个我的解决方案把
就官方这个态度,issue 提了那么久都不理,其他的不多说。主要思路就是清理 uniapp 在 Android 本地的缓存
注意:此代码为 android 原生代码,kotlin 实现,不是 js 代码

//找到 uniapp 在 Android 的目录,不同版本的系统这个目录可能不同,但是思路都是一样的
val file = File(requireContext().filesDir, "apps/你的 uniapp 的 id")
 if (file.exists()){
     val isDelSuccess =  FileUtil.deleteDirectoryFiles(file.path)
 }

 /**
     * 删除目录下的文件
     *
     * @param dir
     * 要删除的目录的文件路径
     *
     * @return 目录删除成功返回true,否则返回false
     */
    public fun deleteDirectoryFiles(dir: String): Boolean {
        var path = dir
        // 如果dir不以文件分隔符结尾,自动添加文件分隔符
        if (!path.endsWith(File.separator))
            path += File.separator
        val dirFile = File(path)
        // 如果dir对应的文件不存在,或者不是一个目录,则退出
        if (!dirFile.exists() || !dirFile.isDirectory) {
//            println("删除目录失败:" + dir + "不存在!")
            return false
        }
        var flag = true
        // 删除文件夹中的所有文件包括子目录
        val files = dirFile.listFiles()
        if (files != null && files.isNotEmpty()) {
            for (i in files.indices) {
                // 删除子文件
                if (files[i].isFile) {
                    flag = deleteFile(files[i].absolutePath)
                    if (!flag)
                        break
                } else if (files[i].isDirectory) {
                    flag = deleteDirectory(
                        files[i]
                            .absolutePath
                    )
                    if (!flag)
                        break
                }// 删除子目录
            }
        }
        return flag
    }

from uni-app.

zhetengbiji avatar zhetengbiji commented on September 28, 2024

贴一个我的解决方案把 就官方这个态度,issue 提了那么久都不理,其他的不多说。主要思路就是清理 uniapp 在 Android 本地的缓存

//找到 uniapp 在 Android 的目录,不同版本的系统这个目录可能不同,但是思路都是一样的
val file = File(requireContext().filesDir, "apps/你的 uniapp 的 id")
 if (file.exists()){
     val isDelSuccess =  FileUtil.deleteDirectoryFiles(file.path)
 }

 /**
     * 删除目录下的文件
     *
     * @param dir
     * 要删除的目录的文件路径
     *
     * @return 目录删除成功返回true,否则返回false
     */
    public fun deleteDirectoryFiles(dir: String): Boolean {
        var path = dir
        // 如果dir不以文件分隔符结尾,自动添加文件分隔符
        if (!path.endsWith(File.separator))
            path += File.separator
        val dirFile = File(path)
        // 如果dir对应的文件不存在,或者不是一个目录,则退出
        if (!dirFile.exists() || !dirFile.isDirectory) {
//            println("删除目录失败:" + dir + "不存在!")
            return false
        }
        var flag = true
        // 删除文件夹中的所有文件包括子目录
        val files = dirFile.listFiles()
        if (files != null && files.isNotEmpty()) {
            for (i in files.indices) {
                // 删除子文件
                if (files[i].isFile) {
                    flag = deleteFile(files[i].absolutePath)
                    if (!flag)
                        break
                } else if (files[i].isDirectory) {
                    flag = deleteDirectory(
                        files[i]
                            .absolutePath
                    )
                    if (!flag)
                        break
                }// 删除子目录
            }
        }
        return flag
    }

应该没有不理,你发的帖子中就引用了我跟进的一个帖子中给的临时方案。目前已经确定是缓存问题,给出临时方案后已经转给了其他相关人员处理。
你的这个方案是否经过验证,如果验证过的话,我一并转给相关人员参考。

from uni-app.

wl386123298 avatar wl386123298 commented on September 28, 2024

@zhetengbiji 目前已经验证过了,我们现在就常用这个方法

from uni-app.

zhetengbiji avatar zhetengbiji commented on September 28, 2024

@zhetengbiji 目前已经验证过了,我们现在就常用这个方法

这部分逻辑你们是怎么什么时机使用?安装wgt之前吗?

from uni-app.

wl386123298 avatar wl386123298 commented on September 28, 2024

@zhetengbiji 我们的场景是打包 wgt 解压放assets 里,算是离线了,这部分逻辑放在app 启动的时候,比如启动页或者主页相关的生命周期中判断,比如 onCreate中,我们的项目结构是这样,见下图
0b0ba210941790efaac9fb4ddbf39ef9.png

from uni-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.