Google 驱动器 file.getId() 仅在发布版本中为空
Google drive file.getId() is null only on release build
我正在使用 Google Drive API V2 版本创建文件夹并将文件上传到文件夹中。它在调试版本上工作得很好,但在发布版本中,文件夹的 file.getId() 是 null。
这是它创建的无标题文件夹的图像:https://ibb.co/fJMyAK
您可以在以下位置找到完整的文档:https://developers.google.com/drive/api/v2/folder
File fileMetadata = new File();
fileMetadata.setTitle("Invoices");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = driveService.files().insert(fileMetadata)
.setFields("id")
.execute();
System.out.println("Folder ID: " + file.getId());
我可以看到正在 google 驱动器上创建文件夹,但它显示为无标题。
我已经进入 Google Api 控制台,确保发布构建密钥库 SHA1 密钥正确输入 api 控制台并且包名称正确。
如有任何帮助,我们将不胜感激!
我运行也遇到了这个问题。这是由于 proguard 规则而发生的。它删除了实际需要的 class 。为了修复它,请将以下 link 添加到您的 proguard-rules.pro 文件中。
#Google api and drive rules
-keep class * extends com.google.api.client.json.GenericJson {
*;
}
-keep class com.google.api.services.drive.** {
*;
}
希望对您有所帮助!
我正在使用 Google Drive API V2 版本创建文件夹并将文件上传到文件夹中。它在调试版本上工作得很好,但在发布版本中,文件夹的 file.getId() 是 null。
这是它创建的无标题文件夹的图像:https://ibb.co/fJMyAK
您可以在以下位置找到完整的文档:https://developers.google.com/drive/api/v2/folder
File fileMetadata = new File();
fileMetadata.setTitle("Invoices");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = driveService.files().insert(fileMetadata)
.setFields("id")
.execute();
System.out.println("Folder ID: " + file.getId());
我可以看到正在 google 驱动器上创建文件夹,但它显示为无标题。
我已经进入 Google Api 控制台,确保发布构建密钥库 SHA1 密钥正确输入 api 控制台并且包名称正确。
如有任何帮助,我们将不胜感激!
我运行也遇到了这个问题。这是由于 proguard 规则而发生的。它删除了实际需要的 class 。为了修复它,请将以下 link 添加到您的 proguard-rules.pro 文件中。
#Google api and drive rules
-keep class * extends com.google.api.client.json.GenericJson {
*;
}
-keep class com.google.api.services.drive.** {
*;
}
希望对您有所帮助!