Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Microsoft Graph java Sdk and proguard for Android release

I use msgraph-sdk-java in my Android application mainly to access OneDrive. In debug mode everything is ok but when I compile in release mode with minify enabled, i have an issue.

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

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

and

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)

Here is the return of gradlew myapp:dependencies where the javax.ws.rs appears.

+--- 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?

Here is what I tried in my proguard-rules.pro file:

-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.** { *; }

my build.gradle where i must exclude META-INF/jersey-module-version' because this file is present in com.sun.jersey:jersey-server:1.19.4 and 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()
}

I have tried many things but I have no ideas. Thanks for your help.

like image 642
Aristide13 Avatar asked Apr 20 '26 13:04

Aristide13


1 Answers

This fixed the issue for me :

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'
}

Also make sure to make the respective pro-gaurd entries to retain com.sun.* classes.

like image 149
Samhith G B Avatar answered Apr 22 '26 03:04

Samhith G B