gpt4 book ai didi

java - Android GoogleCredential 调试与发布

转载 作者:行者123 更新时间:2023-11-29 05:11:13 24 4
gpt4 key购买 nike

我正在尝试读取我的 GCS 存储桶,但看到了一个有趣的行为。通过 Android Studio(作为调试变体)运行我的应用程序时,我能够下载对象。当我创建签名 APK(或作为发布变体运行)时,我无法再下载对象并收到 404 错误。

这是我的授权方式:

GoogleCredential googleCredential = null;
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();

/** Authorizes the installed application to access user's protected data. */
public GoogleCredential authorize() throws Exception {
String p12Password = "****";
String keyAlias = "****";
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(getResources().openRawResource(R.raw.gcskeystore), p12Password.toCharArray());

PrivateKey privateKey = (PrivateKey)keystore.getKey(keyAlias, p12Password.toCharArray());

Set<String> scopes = new HashSet<String>();
scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);

String emailAddress = "********@developer.gserviceaccount.com";

GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(emailAddress)
.setServiceAccountPrivateKey(privateKey)
.setServiceAccountScopes(scopes)
.build();

return credential;
}

打印出我的凭证,运行时是这样的:

com.google.api.client.googleapis.auth.oauth2.GoogleCredential@42ed8060

当我收到错误时:

bpr@46096240

由于在创建签名版本时出现问题,我认为我的 proguard-rules 出错了,但我添加的唯一一行是:

-dontwarn sun.misc.*

希望有人以前见过这种行为!任何帮助将不胜感激!!

珍妮

最佳答案

我能够解决我的问题。我深入研究了 proguard-rules。进行此更新解决了我的问题:

# Needed to keep generic types and @Key annotations accessed via reflection

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}

# Needed by Guava
# See https://groups.google.com/forum/#!topic/guava-discuss/YCZzeCiIVoI

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue

# Needed by google-http-client-android when linking against an older platform version

-dontwarn com.google.api.client.extensions.android.**

# Needed by google-api-client-android when linking against an older platform version

-dontwarn com.google.api.client.googleapis.extensions.android.**

关于java - Android GoogleCredential 调试与发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28384643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com