我正在尝试下载 Firebase 存储目录中名为 1.pdf、2.pdf ... 的所有文件 该代码在 Debug模式下工作,但在 Release模式下不起作用。我一整天都被困在这个问题上。 我认为它可能是来自另一个类的线程,但说实话我不知道。
从 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();
}
最佳答案
将这些添加到您的 proguard-rules.pro
-keep class com.firebase.** { *; }
-keepattributes *Annotation*
-keepattributes Signature
-keep class YOUR_PACKAGE_NAME.YourActivity { *; }
关于java - 从 Firebase 下载文件 |应用程序可以在 Debug模式下运行,但不能在 Release模式下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60995724/