aws-sdk-android icon indicating copy to clipboard operation
aws-sdk-android copied to clipboard

Neither aws-android-sdk-iot nor org.eclipse.paho.client.mqttv3 provide appropriate ProGuard/R8 rules

Open azabost opened this issue 2 years ago • 1 comments

Describe the bug When aws-android-sdk-iot is used in an Android app with R8/ProGuard enabled, then the essential code gets removed and the library doesn't work properly.

For example, I stumbled upon this exception (stacktrace deobfuscated by retrace):

java.util.MissingResourceException: Error locating the logging class
	at org.eclipse.paho.client.mqttv3.logging.LoggerFactory.getLogger(LoggerFactory.java:76)
	at org.eclipse.paho.client.mqttv3.TimerPingSender.<init>(TimerPingSender.java:34)
	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:317)
	at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.connect(AWSIotMqttManager.java:918)
	at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.connect(AWSIotMqttManager.java:869)

In that particular case, I guess that, ideally, it should be fixed in https://github.com/eclipse/paho.mqtt.java/ and I've already found an open issue there (https://github.com/eclipse/paho.mqtt.java/issues/776) but it's very old and nobody seems to care, so perhaps at least you could fix it on your side instead?

To Reproduce Just try to invoke AWSIotMqttManager.connect in a build where code shrinking was enabled, e.g. release in this case:

android {  
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true // <-- this
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
}

Which AWS service(s) are affected? aws-android-sdk-iot

Expected behavior The library can successfully connect and function properly.

Screenshots n/a

Environment Information (please complete the following information):

  • AWS Android SDK Version: com.amazonaws:aws-android-sdk-iot:2.73.0
  • Android Gradle Plugin version: com.android.tools.build:gradle:8.1.3 (implies android.enableR8.fullMode=true)
  • Device: doesn't matter
  • Android Version: doesn't matter
  • Specific to simulators: No

Additional context n/a

azabost avatar Nov 09 '23 17:11 azabost

Thank you for the report. We will look on improving our proguard rules for IoT.

tylerjroach avatar Nov 17 '23 18:11 tylerjroach