java - Android 版本的 Microsoft Graph java Sdk 和 proguard 问题

标签 java android microsoft-graph-api proguard

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

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

DefaultHttpProvider[sendRequestInternal] - 370Error during http request Throwable detail: com.microsoft.graph.core.ClientException: Error during http request..

com.microsoft.graph.core.ClientException: Error during http requ at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(:368) at com.microsoft.graph.http.DefaultHttpProvider.access$000(:53) at com.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) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl at javax.ws.rs.ext.RuntimeDelegate.findDelegate(:122) at javax.ws.rs.ext.RuntimeDelegate.getInstance(:91) at javax.ws.rs.core.UriBuilder.newInstance(:69) at javax.ws.rs.core.UriBuilder.fromUri(:80) at com.microsoft.graph.http.BaseRequest.getRequestUrl(:147) at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(:239)

这是 gradlew myapp:dependencies 的返回值,其中出现了 javax.ws.rs

+--- 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()
}

我尝试了很多东西,但我没有想法。感谢您的帮助。

最佳答案

这解决了我的问题:

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.* 类。

关于java - Android 版本的 Microsoft Graph java Sdk 和 proguard 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56445698/

相关文章:

excel - Microsoft Graph API 访问 Excel 文档权限

java - 安卓本地数据库

java - 如何在 Android 上使用 Cognito/UserPool 登录后实现注销

java - GCM 多行通知

Android 操作栏?

c# - SDK v5 中的 ms.Graph 'groups' 中的分页

microsoft-graph-api - 无法通过 API 更改文件夹名称的大小写

java - 即使在 maven 构建中 java_home 指向 jdk1.7 时,1.3 错误中不支持 generic

java - 我如何检查数组列表是否包含某个字符串

java - PHP 在 sql 查询中使用 $_GET 不返回结果