【问题标题】:Downloading files from Firebase | App works in debug but not release mode从 Firebase 下载文件 |应用程序在调试但不是发布模式下工作
【发布时间】:2020-04-02 15:53:19
【问题描述】:

我正在尝试下载名为 1.pdf、2.pdf 的 Firebase 存储目录中的所有文件... 该代码在调试模式下工作,但在发布时不起作用。我整天都被困在这上面。 我认为它可能是来自另一个类的线程,但老实说我不知道​​。

从 Firebase 获取文件的代码:

   for (int i = 1; i < 10000; i++) {
        StorageReference ref = storageRef.child("FirstTimeForms/" + i + ".pdf");
        File localFile = File.createTempFile("Form", ".pdf");
        FileDownloadTask dm = ref.getFile(localFile);
        int fileSize = Integer.parseInt(String.valueOf(localFile.length()/1024));

        if(fileSize > 0){
            fileManager.copyFile(localFile, new File("/sdcard/Download/Forms/" + i + ".pdf"));
        }else{
            return;
        }
    }

将从缓存下载的文件复制到 SD 的代码

  FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try
        {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        }
        finally
        {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }

【问题讨论】:

    标签: java android firebase firebase-storage


    【解决方案1】:

    在你的 proguard-rules.pro 中添加这些

    -keep class com.firebase.** { *; }
    -keepattributes *Annotation*
    -keepattributes Signature
    
    -keep class YOUR_PACKAGE_NAME.YourActivity { *; }
    
    

    【讨论】:

    • 我以前从未编辑过 proguard 规则。但认为我做对了,把它们粘贴进去并重建。这是正确的吗?
    • 我更新了我的答案,希望这会奏效,再试一次
    猜你喜欢
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2018-03-22
    相关资源
    最近更新 更多