GoogleClentientSecrets在调试构建中工作,但未在发行版中进行



我的代码在调试模式下正常工作,但在发行版中不起作用。

GoogleClientSecrets clientSecrets =
                GoogleClientSecrets.load(
                        JacksonFactory.getDefaultInstance(), new InputStreamReader(getAssets().open(Constants.CLIENT_SECRET_FILE)));
        clientSecrets.getWeb().toPrettyString();

我已经检查了JacksonFactoryinputstreaminputstreamreader都不是无效的。并且对象clientSecrets具有带有" Web"标签的JSON。我可以用clientSecrets.toPrettyString();

打印JSON

但是clienterecrets.getweb((正在返回null。" Web"必须无效才能进一步进行,因为它是分解文件中的先决条件。

public final class GoogleClientSecrets extends GenericJson {
...
 public Details getDetails() {
  // that web or installed, but not both
  Preconditions.checkArgument((web == null) != (installed == null));
  return web == null ? installed : web;
 }
...
}

这是我的gradle文件

    apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
    applicationId "com.santra.sanchita.portfolioapp"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    packagingOptions {
    pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
    exclude 'META-INF/gfprobe-provider.xml'
    exclude 'META-INF/hk2-locator/default'
    exclude 'META-INF/javamail.charset.map'
    exclude 'META-INF/javamail.default.address.map'
    exclude 'META-INF/javamail.default.providers'
    exclude 'META-INF/mailcap'
    exclude 'META-INF/mailcap.default'
    exclude 'META-INF/mimetypes.default'
    exclude 'META-INF/rxjava.properties'
    exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
    }
    testOptions {
    unitTests.returnDefaultValues = true
    }
}
greendao {
    schemaVersion 1
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:multidex:$rootProject.ext.multidexVersion"
    implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.ext.supportLibraryVersion"
    implementation "com.android.support:support-dynamic-animation:$rootProject.ext.supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$rootProject.ext.supportLibraryVersion"
    implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constrainLayoutVersion"
    implementation "com.google.android.gms:play-services-auth:$rootProject.ext.googlePlayServicesVersion"
    implementation "com.google.api-client:google-api-client:$rootProject.ext.googleClientLibraryVersion"
    //java mail
    implementation "com.sun.mail:android-mail:$rootProject.ext.javaMailVersion"
    implementation "com.sun.mail:android-activation:$rootProject.ext.javaMailVersion"
    //logs
    implementation "com.jakewharton.timber:timber:$rootProject.ext.timerLoggerVersion"
    // dependency injection
    implementation "com.google.dagger:dagger:$rootProject.ext.daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion"
    provided "javax.annotation:jsr250-api:$rootProject.ext.javaxAnnotationVersion"
    implementation "javax.inject:javax.inject:$rootProject.ext.javaxInjectVersion"
    // code generator for view
    implementation "com.jakewharton:butterknife:$rootProject.ext.butterKnifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterKnifeVersion"
    // database
    implementation "org.greenrobot:greendao:$rootProject.ext.greenDaoVersion"
    implementation "net.zetetic:android-database-sqlcipher:$rootProject.ext.sqlcipherVersion"
    //retrofit
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofitVersion"
    //rxjava
    implementation "io.reactivex.rxjava2:rxjava:$rootProject.ext.rxJavaVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$rootProject.ext.rxJavaAndroidVersion"
    implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:$rootProject.ext.rxJavaRetrofitAdapterVersion"
    //unit testing
    implementation "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"
    testImplementation "junit:junit:$rootProject.ext.junitVersion"
    testImplementation "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
    testImplementation "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
    testImplementation "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
    testImplementation "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"
    androidTestImplementation "com.android.support.test:runner:$rootProject.ext.runnerVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
}
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.ext.supportLibraryVersion"
    resolutionStrategy.force "com.google.code.findbugs:jsr305:$rootProject.ext.findBugsVersion"
    exclude module: 'httpclient'
    exclude module: 'commons-logging'
}
apply plugin: 'com.google.gms.google-services'

这是我的proguard文件

    -dontwarn org.apache.http.**
-dontwarn org.apache.commons.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn org.greenrobot.greendao.**
-dontwarn okio.DeflaterSink
-dontwarn okio.Okio
-dontwarn retrofit2.Platform$Java8
-dontwarn com.sun.mail.handlers.handler_base
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
    public static java.lang.String TABLENAME;
}
-keep class **$Properties
-keep class com.google.api.client.json.jackson2.JacksonFactory
-keep class sun.nio.cs.StreamDecoder
-keep class com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets
-keep class com.google.api.client.json.JsonFactory

我缺少发布的版本?

问题是proguard文件。仅保留GoogleClecteCrets的班级名称无效。我必须保留所有变量和方法。

-keep class com.google.api.client.json.jackson2.JacksonFactory { *; }
-keep class sun.nio.cs.StreamDecoder { *; }
-keep class com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets { *; }
-keep class com.google.api.client.json.JsonFactory { *; }

最新更新