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

[Flutter-Android] [R8-Proguard] Minify issue, missing classes when build app. #1712

Open
hoyiliang opened this issue Oct 18, 2024 · 1 comment
Labels
Communication - Chat customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@hoyiliang
Copy link

hoyiliang commented Oct 18, 2024

Good day, we will refer to the following error log.

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in .../build/app/outputs/mapping/qaRelease/missing_rules.txt.
ERROR: R8: Missing class aQute.bnd.annotation.spi.ServiceProvider (referenced from: com.ctc.wstx.dtd.DTDSchemaFactory and 5 other contexts)
Missing class com.sun.activation.registries.LogSupport (referenced from: void javax.activation.MailcapCommandMap.<init>()  @and 4 other contexts)
Missing class com.sun.activation.registries.MailcapFile (referenced from: com.sun.activation.registries.MailcapFile[] javax.activation.MailcapCommandMap.DB and 5 other contexts)
Missing class java.awt.datatransfer.DataFlavor (referenced from: java.awt.datatransfer.DataFlavor[] javax.activation.DataHandler.emptyFlavors and 4 other contexts)
Missing class java.awt.datatransfer.Transferable (referenced from: javax.activation.DataHandler)
Missing class java.beans.BeanInfo (referenced from: void org.apache.log4j.config.PropertySetter.introspect())
Missing class java.beans.IntrospectionException (referenced from: void org.apache.log4j.config.PropertySetter.introspect())
Missing class java.beans.Introspector (referenced from: void org.apache.log4j.config.PropertySetter.introspect() and 2 other contexts)
Missing class java.beans.PropertyDescriptor (referenced from: java.beans.PropertyDescriptor[] org.apache.log4j.config.PropertySetter.props and 4 other contexts)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyQaReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

After some research around the web, I am expected to add some keep rules into proguard-rules.pro file to keep the classes that the SDK requires.

Some notes:

  1. Only happens when building in Release mode because the build script only enables Minify in Release mode by default.
  2. Using -dontwarn in the missing_rules.txt is not the solution. The app crashes when I try to call the SDK's methods.
  3. I have tried to include the following keep rules, but the app still crashes when I call the SDK's methods.:
-keep class aQute.* { *; }
-keep class com.sun.* { *; }
-keep class java.awt.* { *; }
-keep class java.beans.* { *; }
-keep class com.skype.rt.** {*;}
-keep class com.azure.** {*;}
-keep class com.skype.android.** {*;}
-keep class com.microsoft.media.** {*;}
-keep class com.microsoft.dl.** {*;}
  1. The libraries I am using, reference: https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?tabs=windows&pivots=programming-language-android
build.gradle
dependencies {
    implementation "com.azure.android:azure-communication-common:1.2.1"
    implementation "com.azure.android:azure-communication-chat:2.0.3"
    implementation "org.slf4j:slf4j-log4j12:1.7.29"
}

Please assist on this issue. Preferably I do not need to disable the Minify feature enabled by default.

Thanks!

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Oct 18, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Oct 21, 2024
@hoyiliang
Copy link
Author

hoyiliang commented Nov 20, 2024

Update:

I found a working combination of entries in app level build.gradle and proguard-rules.pro. With these, I am able to build and call the SDK methods without error/crash.

However, I am unsure if the versions I chose for some libraries are appropriate (as in not too old/new).

If anyone has a better library version selections, or found out there are still some library missing, I greatly appreciate it if you could share.

The libraries that I am unsure of are:

implementation "biz.aQute.bnd:biz.aQute.bnd.annotation:6.1.0"

implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '3.1.0'
implementation 'com.fasterxml:aalto-xml:1.2.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1'

implementation "org.slf4j:slf4j-api:1.7.36"
implementation "org.slf4j:slf4j-simple:1.7.36"
build.gradle
dependencies {
        // Azure Communication Service SDK
        implementation "com.azure.android:azure-core:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-logging:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-http:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-http-okhttp:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-http-httpurlconnection:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-jackson:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-rest:1.0.0-beta.14"
        implementation "com.azure.android:azure-core-credential:1.0.0-beta.14"

        implementation "com.azure.android:azure-communication-common:1.2.1"
        implementation "com.azure.android:azure-communication-chat:2.1.0"
        implementation "com.microsoft:trouter-client-android:0.1.1"
        implementation "biz.aQute.bnd:biz.aQute.bnd.annotation:6.1.0"

        implementation group: 'org.apache.poi', name: 'poi-ooxml', version: ‘4.1.2’
        implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '3.1.0'
        implementation 'com.fasterxml:aalto-xml:1.3.2’
        implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.7.1'

        implementation "org.slf4j:slf4j-api:1.7.36"
        implementation "org.slf4j:slf4j-simple:1.7.36"
}
proguard-rules.pro
# ACS Chat & Dependencies
-dontwarn com.sun.activation.registries.LogSupport
-dontwarn com.sun.activation.registries.MailcapFile
-dontwarn java.awt.datatransfer.DataFlavor
-dontwarn java.awt.datatransfer.Transferable

-keep class javax.xml.stream.** { *; }
-keep class com.bea.xml.stream.** { *; }
-keep class com.azure.android.** { *; }
-keep class com.skype.** { *; }
-keep class com.microsoft.trouterclient.** { *; }
-keep class com.fasterxml.jackson.databind.ser.std.ClassSerializer { *; }
-keep class com.fasterxml.jackson.core.** { *; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Communication - Chat customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants