Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proguard issue with Android release #258

Closed
fiasko131 opened this issue Jun 4, 2019 · 23 comments · Fixed by #449
Closed

Proguard issue with Android release #258

fiasko131 opened this issue Jun 4, 2019 · 23 comments · Fixed by #449
Assignees
Milestone

Comments

@fiasko131
Copy link

fiasko131 commented Jun 4, 2019

Is this sdk really usable on Adroid?

I am referring to this post issue #213

I also posted on Stack Overflow with more details .

Please keep us informed as we have been spending time to migrate from onedrive-sdk-android which seems no longer maintained and no longer works with Pie.

Thanks

Steps to reproduce the behavior
Import android-java-connect-sample
Replace the app gradle file by this:

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 'your password'
            storeFile file('the path of your keyt.jks')
            storePassword 'your password'
        }
        debug {
            keyAlias 'key0'
            keyPassword 'your password'
            storeFile file('the path of your keyt.jks')
            storePassword 'your password'
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            proguardFile 'the path of your proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
            debuggable true
             proguardFile 'the path of your proguard-rules.pro'
        }
    }
    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:28.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    // Include the SDK as a dependency
    implementation 'com.microsoft.graph:microsoft-graph:1.4.0'
    implementation 'com.microsoft.graph:microsoft-graph-android-auth:0.1.0-SNAPSHOT'
    // 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:25.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'

}

proguard-rules.pro

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

-keep class com.sun.** { *; }
-keep class com.sun.**
-keep interface com.sun.** { *; }
@fiasko131 fiasko131 changed the title Proguard issue Proguard issue with Android release Jun 4, 2019
@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

I am using the following Proguard rules. I wonder if they can be narrowed down further

`-keepnames class com.microsoft.** { ; } #better in crash logs
-keep class com.microsoft.identity.common.internal.providers.microsoft.
* { *; } #prevent failed authentication AzureAD/microsoft-authentication-library-for-android#613

#This enum is accessed via reflection in common msal lib thus proguard removes it.
-keep public enum com.microsoft.identity.common.internal.ui.AuthorizationAgent { *; }
-keep class com.microsoft.identity.common.internal.cache.**{ *; }

#Classes for below package is used by MSAL library. Ignore warning coming from the dependency.
-dontwarn com.nimbusds.jose.**
-keepnames class com.sun.** { ; } #prevent crash on upload with r8
-keepnames class javax.ws.
* { ; } #prevent crash on upload with r8
-keepnames class com.microsoft.
* { *; } #prevent crash of JSON parsing related to enum ADAL`

@fiasko131
Copy link
Author

fiasko131 commented Jun 5, 2019

@NLLAPPS
It does not change anything for me.
Always the same issue with 1.4.0:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.ws.rs.ext.RuntimeDelegateImpl"

Do you use Drive part?

@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

Yes I do. Are you sue rules are applied?

@fiasko131
Copy link
Author

fiasko131 commented Jun 5, 2019

Yes because I had a synthax error with your rules ... it is missing "*" on some (*;)
And it is not tested with my project but with the microsoft connect sample ... you use the 1.4.0?

@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

implementation 'com.microsoft.identity.client:msal:0.3.1-alpha'
implementation 'com.microsoft.graph:microsoft-graph:1.4.0'

@fiasko131
Copy link
Author

fiasko131 commented Jun 5, 2019

if i add
implementation 'com.microsoft.identity.client:msal:0.3.1-alpha'
I have errors in the code ... it changes the logic of AuthenticationManager ??

I have already:
implementation 'com.microsoft.graph:microsoft-graph-android-auth:0.1.0-SNAPSHOT'

@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

Yes, there are some changes I had to implement

@fiasko131
Copy link
Author

and it's ok with proguard?
Can you give me your modifications?

@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

It is OK in my app. I cannot provide it. It is integrated in to my app unfortunately. MSAL sample android app has commits that shows changes

@fiasko131
Copy link
Author

But why Microsoft is so tricky???
I spent time to migrate from One-drive-sdk to msgraph sdk for java...issues...then remigrate to msgraph sdk for android ...and so on...
The docs are very unclear to make a choice and support very poor!

Thanks for your help.

is there a way to mamage multi account ?

@NLLAPPS
Copy link

NLLAPPS commented Jun 5, 2019

I've asked this few time in their issue trackers. The main issue is finding out what is what and when to implement. There are a lot of abandoned projects, un-documented projects/sdks
I have spent 2 months on One Drive implementations.

Re: Multi account. I think it is being implemented. I am following commits to https://github.com/Azure-Samples/ms-identity-android-native/ for example https://github.com/Azure-Samples/ms-identity-android-native/pull/21/files

@fiasko131
Copy link
Author

fiasko131 commented Jun 5, 2019

So I made the changes. it's ok in debug but still the same issue in release. It's ok with R8 off !!!

Thanks a lot for your links

@NakulSabharwal
Copy link
Contributor

@fiasko131 @NLLAPPS msgraph-sdk-java is usable on Android, the older msgraph-sdk-android is going to be deprecated and replaced by msgraph-sdk-java. Have you tested this Proguard issue along with msgraph-sdk-java ?

@NLLAPPS
Copy link

NLLAPPS commented Jun 6, 2019 via email

@fiasko131
Copy link
Author

fiasko131 commented Jun 6, 2019

@NakulSabharwal

Did you read my first post?

I migrated to msgraph-sdk-java from one-drive-sdk for android and got this issue with proguard R8.

To reproduce the behavior just test with android-java-connect-sample as explained in my first post.
The only solution I found is to disable R8 in android studio and it does not please me!

Please be more clear about the usable libraries because I have just migrated back to msgraph-sdk-android !!

@fiasko131
Copy link
Author

fiasko131 commented Jun 7, 2019

@NLLAPPS
Are you sure your R8 is enabled?

@NLLAPPS
Copy link

NLLAPPS commented Jun 7, 2019 via email

@SailReal
Copy link
Contributor

SailReal commented Jul 9, 2019

@fiasko131 I'm having the same issue: switched tomicrosoft-graph because of the not updated microsoft-graph-android. But together with microsoft-graph-android-auth and enabled R8 always getting Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.ws.rs.ext.RuntimeDelegateImpl" at run time and just in release mode.

Edit: If I add the entries of your starting post to the proguard file (with R8 enabled), the ClassNotFoundException isn't thrown and it works as expected:

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

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

@monicager
Copy link

monicager commented Jul 24, 2019

@fiasko131 Have you been able to fix this? Im having the same issue I added all -keep and same issue.

@NLLAPPS
Copy link

NLLAPPS commented Sep 10, 2019 via email

@Samhithgb
Copy link

Was anyone able to fix this? Getting the same error.

@maxklint
Copy link

Still getting the same error.

@baywet
Copy link
Member

baywet commented Sep 4, 2020

Hey everyone,
Thanks for your feedback and for your patience on the matter.
I've authored #449 which replaces the dependency all together by okhttp (which is already a dependency of the core library)
This should fix this issue which will get closed whenever the pull request gets merged.

@baywet baywet added this to the 2.1.0 milestone Sep 4, 2020
@baywet baywet self-assigned this Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants