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

Android support #213

Closed
SgtSilvio opened this issue Dec 11, 2018 · 8 comments
Closed

Android support #213

SgtSilvio opened this issue Dec 11, 2018 · 8 comments
Assignees

Comments

@SgtSilvio
Copy link
Member

The following has to added to the app build.gradle file

android {
    ...
    packagingOptions {
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/io.netty.versions.properties'
    }
}

And of course this permission has to be added to the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>

@SgtSilvio
Copy link
Member Author

Android should be added to the documentation

@SgtSilvio SgtSilvio changed the title Check Android Android support Jun 22, 2019
@SgtSilvio
Copy link
Member Author

Netty and JCTools can not be proguarded well, so add these proguard rules:

-keepclassmembernames class io.netty.** {
    *;
}

-keepclassmembernames class org.jctools.** {
    *;
}

@SgtSilvio SgtSilvio added this to To do in Version 1.1.x Jun 27, 2019
@SgtSilvio
Copy link
Member Author

Works on API 24+ (Android 7.0+)

Lambdas, method references, static and default methods can be compiled to lower versions by specifying:

android {
    ...
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    ...
}

Unfortunately java.util.function.*, java.util.Optional, java.util.concurrent.CompletableFuture are only available on API 24+
Reference: https://developer.android.com/studio/write/java8-support

@SgtSilvio
Copy link
Member Author

SgtSilvio commented Jul 5, 2019

Ignore this comment, Proguard 6.1 does not seem to work smoothly

Proguard 6.1 supports backporting streams (including java.util.function.*, java.util.Optional)
Unfortunately java.util.concurrent.CompletableFuture can not be backported yet.
https://www.guardsquare.com/en/blog/proguard-61-released

The following needs to be specified in gradle.properties:

android.enableR8=false
android.enableR8.libraries=false

The following needs to be specified in the top-level build.gradle:

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'net.sf.proguard:proguard-gradle:6.1.1'
    }
    configurations.all {
        resolutionStrategy {
            force 'net.sf.proguard:proguard-gradle:6.1.1'
        }
    }
    ...
}

The following proguard rule needs to be added:

-target 1.7

Also other proguard rules are necessary, but it is not clear yet, which are necessary.

@shriharsha-bhagwat
Copy link

shriharsha-bhagwat commented Jul 12, 2019

So there is no way i can use following/similar on API level < 23 ?

mClient.toAsync().subscribeWith()
                            .topicFilter(topic)
                            .qos(MqttQos.EXACTLY_ONCE)
                            .callback(new Consumer<Mqtt3Publish>() {
                                @Override
                                public void accept(Mqtt3Publish mqtt3Publish) {
                                    //Do something
                                    Log.e(HiveMqttService.class.getSimpleName(),
                                            mqtt3Publish.getTopic().toString());
                                }
                            })
                            .send()
                            .whenComplete((subAck, throwable) -> {
                                if (throwable == null) {
                                     //Do something
                                    Log.e(HiveMqttService.class.getSimpleName(), "Subscribed " + topic);
                                } else {
                                    Log.e(HiveMqttService.class.getSimpleName(), "Error on " + topic + " " + throwable.getMessage());
                                }
                             });

@SgtSilvio
Copy link
Member Author

The gradle plugin Android RetroFix can backport java.util.function.*, java.util.Optional, java.util.concurrent.CompletableFuture and more.

@shriharsha-bhagwat
Copy link

Wow cool. Thanks a lot. This MQTT Client Library is the best.

@SgtSilvio
Copy link
Member Author

Android Support is now documented here: https://hivemq.github.io/hivemq-mqtt-client/docs/installation/android.html

@SgtSilvio SgtSilvio moved this from To do to In progress in Version 1.1.x Jul 22, 2019
@SgtSilvio SgtSilvio moved this from In progress to Review in progress in Version 1.1.x Jul 22, 2019
@SgtSilvio SgtSilvio moved this from Review in progress to Done in Version 1.1.x Jul 22, 2019
@SgtSilvio SgtSilvio self-assigned this Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Version 1.1.x
  
Done
Development

No branches or pull requests

2 participants