首页 > 解决方案 > Microsoft Graph java Sdk 和 Android 版本的 proguard 问题

问题描述

我在我的 Android 应用程序中使用msgraph-sdk-java主要是为了访问 OneDrive。在调试模式下一切正常,但是当我在启用缩小的发布模式下编译时,我遇到了问题。

mGraphServiceClient.me().drive().root().children().buildRequest();

DefaultHttpProvider[sendRequestInternal] - http 请求期间出现 370Error 可抛出的详细信息:com.microsoft.graph.core.ClientException:http 请求期间出错..

com.microsoft.graph.core.ClientException:在 com.microsoft.graph.http.DefaultHttpProvider.access$000(:53) 在 com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(:368) 的 http 请求期间出错。 microsoft.graph.http.DefaultHttpProvider$1.run(:155) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)在 java.lang.Thread.run(Thread.java:764) 引起:java.lang.RuntimeException:java.lang.ClassNotFoundException:com.sun.ws.rs.ext.RuntimeDelegateImpl在 javax.ws.rs.ext.RuntimeDelegate.findDelegate(:122) 在 javax.ws.rs.ext.RuntimeDelegate.getInstance(:91) 在 javax.ws.rs.core.UriBuilder.newInstance(:69) 在 javax .ws.rs.core.UriBuilder.fromUri(:80) 在 com.microsoft.graph.http.BaseRequest.getRequestUrl(:147) 在 com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(:239)

这是javax.ws.rs出现的 gradlew myapp:dependencies 的返回。

+--- com.microsoft.graph:microsoft-graph:1.4.+ -> 1.4.0
    |    +--- org.apache.commons:commons-math3:3.6.1
    |    +--- com.google.code.gson:gson:2.8.2
    |    \--- com.sun.jersey:jersey-server:1.19.4
    |         \--- com.sun.jersey:jersey-core:1.19.4
    |              \--- javax.ws.rs:jsr311-api:1.1.1// <----here?

这是我在 proguard-rules.pro 文件中尝试的内容:

-keep class com.microsoft.** { *; }
-keep class com.microsoft.**
-keep interface com.microsoft.** { *; }
-keepclasseswithmembernames class com.microsoft.** { *; }

-keep class com.sun.ws.** { *; }
-keep class com.sun.ws.**
-keep interface com.sun.ws.** { *; }

-keep class com.sun.jersey.** { *; }
-keep class com.sun.jersey.**
-keep interface com.sun.jersey.** { *; }

我的 build.gradle 必须排除 META-INF/jersey-module-version',因为该文件存在于 com.sun.jersey:jersey-server:1.19.4 和 com.sun.jersey:jersey-core:1.19 中。 4:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    flavorDimensions "default"
    defaultConfig {
        applicationId "com.microsoft.graph.connect"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 2
        versionName "2.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        release {
            keyAlias 'key0'
            keyPassword 'tototo'
            storeFile file('D:/android-java-connect/connect.jks')
            storePassword 'tototo'
        }
        debug {
            keyAlias 'key0'
            keyPassword 'tototo'
            storeFile file('D:/android-java-connect/connect.jks')
            storePassword 'tototo'
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            proguardFile 'D:/sauvegarde/work_space_test/onedrive/proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
            debuggable true
        }
    }
    productFlavors {
        legacyDebug {
            minSdkVersion 17
        }
        modernDebug {
            minSdkVersion 21
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    configurations {
        all {
            resolutionStrategy.force 'com.android.support:support-annotations:25.3.1'
        }
    }
    dexOptions {
        preDexLibraries = false
        jumboMode = true
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
        exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
        exclude 'META-INF/jersey-module-version'
    }
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.1.1'

    implementation ('com.microsoft.identity.client:msal:0.1.+') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    implementation 'com.android.volley:volley:1.1.0'
    // Include the SDK as a dependency
    //implementation 'com.microsoft.graph:msgraph-sdk-android:1.3.2'
    implementation('com.microsoft.graph:microsoft-graph:1.4.+')

    // Include GSON as a dependency
    implementation 'com.google.code.gson:gson:2.6.2'
    implementation 'commons-io:commons-io:2.0.1'
    // Test libraries
    androidTestImplementation 'com.android.support:support-annotations:26.3.1'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test:rules:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:2.2.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-web:2.2.2'
}

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
    }
    repositories {
        google()
    }
}

repositories {
    google()
}

我尝试了很多东西,但我没有任何想法。谢谢你的帮助。

标签: javaandroidmicrosoft-graph-apiproguard

解决方案


这为我解决了这个问题:

implementation('com.microsoft.graph:microsoft-graph:1.6.0'){
    exclude group: 'com.sun.jersey', module: 'jersey-core'
    exclude group: 'com.sun.jersey', module: 'jersey-server'
}

implementation(group: 'com.sun.jersey', name: 'jersey-bundle', version: '1.19.4'){
    exclude group: 'javax.ws.rs', module: 'jsr311-api'
}

还要确保制作相应的 pro-gaurd 条目以保留 com.sun.* 类。


推荐阅读