{"action":"created","issue":{"url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/571","repository_url":"https://api.github.com/repos/chkr1011/MQTTnet","labels_url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/571/labels{/name}","comments_url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/571/comments","events_url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/571/events","html_url":"https://github.com/chkr1011/MQTTnet/issues/571","id":419243252,"node_id":"MDU6SXNzdWU0MTkyNDMyNTI=","number":571,"title":"ClassNotFoundException: Didn't find class \"java.util.Optional\"","user":{"login":"bangonkali","id":539946,"node_id":"MDQ6VXNlcjUzOTk0Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/539946?v=4","gravatar_id":"","url":"https://api.github.com/users/bangonkali","html_url":"https://github.com/bangonkali","followers_url":"https://api.github.com/users/bangonkali/followers","following_url":"https://api.github.com/users/bangonkali/following{/other_user}","gists_url":"https://api.github.com/users/bangonkali/gists{/gist_id}","starred_url":"https://api.github.com/users/bangonkali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangonkali/subscriptions","organizations_url":"https://api.github.com/users/bangonkali/orgs","repos_url":"https://api.github.com/users/bangonkali/repos","events_url":"https://api.github.com/users/bangonkali/events{/privacy}","received_events_url":"https://api.github.com/users/bangonkali/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-03-10T22:47:46Z","updated_at":"2019-03-11T01:08:27Z","closed_at":null,"author_association":"NONE","body":"Some background info. We're looking in to moving from a legacy [Xamarin Android + MQTTNet](https://github.com/chkr1011/MQTTnet) to hopefully a Flutter based implementation with native Kotlin service bindings. The App is designed to act as a short term server for embedded devices. Same strategy has worked with [Xamarin Android + MQTTNet](https://github.com/chkr1011/MQTTnet) only the next version is planned to be implemented using Flutter. \r\n\r\n### Expected behavior\r\n\r\nServer runs\r\n\r\n### Actual behavior\r\n\r\nProblem areas are calls to `Optional` class. This feels like I just missed something very basic. Only the calls to `Optional.xxx()` is causing the issue, as in the case below.\r\n\r\n**/io/moquette/broker/NewNettyAcceptor.class**\r\n``` java\r\n        boolean useFineMetrics = props.boolProp(\"use_metrics\", false);\r\n        if (useFineMetrics) {\r\n            DropWizardMetricsHandler metricsHandler = new DropWizardMetricsHandler();\r\n            metricsHandler.init(props);\r\n            this.metrics = Optional.of(metricsHandler);\r\n        } else {\r\n            this.metrics = Optional.empty();\r\n        }\r\n```\r\n\r\n```\r\n Caused by: java.lang.ClassNotFoundException: Didn't find class \"java.util.Optional\" on path: DexPathList[[zip file \"/data/app/com.company.myapp-2/base.apk\"],nativeLibraryDirectories=[/data/app/com.company.myapp-2/lib/arm, /data/app/com.company.myapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]\r\n```\r\n\r\n**Full Error**\r\n\r\n```\r\n03-11 06:18:49.873 8832-8832/com.company.myapp.service.process E/AndroidRuntime: FATAL EXCEPTION: main\r\n    Process: com.company.myapp.service.process, PID: 8832\r\n    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Optional;\r\n        at io.moquette.broker.NewNettyAcceptor.initialize(NewNettyAcceptor.java:140)\r\n        at io.moquette.broker.Server.startServer(Server.java:190)\r\n        at io.moquette.broker.Server.startServer(Server.java:135)\r\n        at io.moquette.broker.Server.startServer(Server.java:122)\r\n        at com.company.myapp.moquette.MoquetteBroker.start(MoquetteBroker.kt:60)\r\n        at com.company.myapp.MyAppService.startMoquette(MyAppService.kt:30)\r\n        at com.company.myapp.MyAppService.onStartCommand(MyAppService.kt:56)\r\n        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)\r\n        at android.app.ActivityThread.-wrap17(ActivityThread.java)\r\n        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)\r\n        at android.os.Handler.dispatchMessage(Handler.java:102)\r\n        at android.os.Looper.loop(Looper.java:148)\r\n        at android.app.ActivityThread.main(ActivityThread.java:5417)\r\n        at java.lang.reflect.Method.invoke(Native Method)\r\n        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)\r\n        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)\r\n     Caused by: java.lang.ClassNotFoundException: Didn't find class \"java.util.Optional\" on path: DexPathList[[zip file \"/data/app/com.company.myapp-2/base.apk\"],nativeLibraryDirectories=[/data/app/com.company.myapp-2/lib/arm, /data/app/com.company.myapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]\r\n        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)\r\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)\r\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)\r\n        at io.moquette.broker.NewNettyAcceptor.initialize(NewNettyAcceptor.java:140) \r\n        at io.moquette.broker.Server.startServer(Server.java:190) \r\n        at io.moquette.broker.Server.startServer(Server.java:135) \r\n        at io.moquette.broker.Server.startServer(Server.java:122) \r\n        at com.company.myapp.moquette.MoquetteBroker.start(MoquetteBroker.kt:60) \r\n        at com.company.myapp.MyAppService.startMoquette(MyAppService.kt:30) \r\n        at com.company.myapp.MyAppService.onStartCommand(MyAppService.kt:56) \r\n        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010) \r\n        at android.app.ActivityThread.-wrap17(ActivityThread.java) \r\n        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442) \r\n        at android.os.Handler.dispatchMessage(Handler.java:102) \r\n        at android.os.Looper.loop(Looper.java:148) \r\n        at android.app.ActivityThread.main(ActivityThread.java:5417) \r\n        at java.lang.reflect.Method.invoke(Native Method) \r\n        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) \r\n        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) \r\n    \tSuppressed: java.lang.ClassNotFoundException: java.util.Optional\r\n        at java.lang.Class.classForName(Native Method)\r\n        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)\r\n        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)\r\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)\r\n        \t\t... 17 more\r\n     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n* Kotlin `ext.kotlin_version = '1.3.21'`\r\n* Flutter `flutter create -i swift -a kotlin `\r\n* Running on Service that is on separate Android process. Btw, the permissions are also being asked during runtime. Also test writes/reads to filesystem were proven to be good.\r\n\r\n    ```\r\n            <service\r\n                android:name=\".MyAppService\"\r\n                android:exported=\"true\"\r\n                android:label=\"MyApp Service\"\r\n                android:process=\"com.company.myapp.service.process\">\r\n\r\n                <intent-filter>\r\n                    <action android:name=\"com.company.myapp.service.notification.action.START_SERVICE\" />\r\n                    <action android:name=\"com.company.myapp.service.notification.action.ACTION_STOP_SERVICE_FROM_NOTIFICATION\" />\r\n                    <action android:name=\"com.company.myapp.service.notification.action.ACTION_START_ACTIVITY_FROM_NOTIFICATION\" />\r\n                    <action android:name=\"com.company.myapp.service.notification.action.ACTION_START_BROKER_FROM_UI\" />\r\n                    <action android:name=\"com.company.myapp.service.notification.action.ACTION_STOP_BROKER_FROM_UI\" />\r\n                </intent-filter>\r\n            </service>\r\n    ```\r\n* Broker Creation\r\n    ```\r\n        if (mqttBroker == null)\r\n        mqttBroker = Server()\r\n\r\n        val properties = Properties()\r\n        properties.setProperty(BrokerConstants.PORT_PROPERTY_NAME, \"1883\")\r\n        properties.setProperty(BrokerConstants.HOST_PROPERTY_NAME, \"0.0.0.0\")\r\n        properties.setProperty(BrokerConstants.ALLOW_ANONYMOUS_PROPERTY_NAME, \"true\")\r\n        properties.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, path)\r\n        properties.setProperty(BrokerConstants.BUGSNAG_ENABLE_PROPERTY_NAME, \"false\")\r\n        properties.setProperty(BrokerConstants.METRICS_ENABLE_PROPERTY_NAME, \"false\")\r\n\r\n        val memoryConfig = MemoryConfig(properties)\r\n        mqttBroker?.startServer(memoryConfig)\r\n        mqttBroker?.addInterceptHandler(MoquettePublisherListener())\r\n    ```\r\n\r\n### Minimal yet complete reproducer code (or URL to code) or complete log file\r\n\r\nCan't produce this now as there is a lot of proprietary code. Working on a redacted code. \r\n\r\n### Moquette MQTT version\r\n```\r\nimplementation 'io.moquette:moquette-broker:0.12'\r\n```\r\n\r\n### JVM version (e.g. `java -version`)\r\n```\r\ndef localProperties = new Properties()\r\ndef localPropertiesFile = rootProject.file('local.properties')\r\nif (localPropertiesFile.exists()) {\r\n    localPropertiesFile.withReader('UTF-8') { reader ->\r\n        localProperties.load(reader)\r\n    }\r\n}\r\n\r\ndef flutterRoot = localProperties.getProperty('flutter.sdk')\r\nif (flutterRoot == null) {\r\n    throw new GradleException(\"Flutter SDK not found. Define location with flutter.sdk in the local.properties file.\")\r\n}\r\n\r\ndef flutterVersionCode = localProperties.getProperty('flutter.versionCode')\r\nif (flutterVersionCode == null) {\r\n    flutterVersionCode = '1'\r\n}\r\n\r\ndef flutterVersionName = localProperties.getProperty('flutter.versionName')\r\nif (flutterVersionName == null) {\r\n    flutterVersionName = '1.0'\r\n}\r\n\r\napply plugin: 'com.android.application'\r\napply plugin: 'kotlin-android'\r\napply from: \"$flutterRoot/packages/flutter_tools/gradle/flutter.gradle\"\r\n\r\nandroid {\r\n    compileSdkVersion 28\r\n\r\n    sourceSets {\r\n        main.java.srcDirs += 'src/main/kotlin'\r\n    }\r\n\r\n    lintOptions {\r\n        disable 'InvalidPackage'\r\n    }\r\n\r\n    defaultConfig {\r\n        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).\r\n        applicationId \"com.company.myapp\"\r\n        minSdkVersion 21\r\n        targetSdkVersion 28\r\n        multiDexEnabled true\r\n        versionCode flutterVersionCode.toInteger()\r\n        versionName flutterVersionName\r\n        testInstrumentationRunner \"android.support.test.runner.AndroidJUnitRunner\"\r\n    }\r\n\r\n    buildTypes {\r\n        release {\r\n            // TODO: Add your own signing config for the release build.\r\n            // Signing with the debug keys for now, so `flutter run --release` works.\r\n            signingConfig signingConfigs.debug\r\n        }\r\n    }\r\n\r\n    packagingOptions {\r\n        exclude 'META-INF/DEPENDENCIES'\r\n        exclude 'META-INF/LICENSE'\r\n        exclude 'META-INF/LICENSE.txt'\r\n        exclude 'META-INF/license.txt'\r\n        exclude 'META-INF/NOTICE'\r\n        exclude 'META-INF/NOTICE.txt'\r\n        exclude 'META-INF/notice.txt'\r\n        exclude 'META-INF/ASL2.0'\r\n        exclude 'META-INF/INDEX.LIST'\r\n        exclude 'META-INF/io.netty.versions.properties'\r\n    }\r\n}\r\n\r\nflutter {\r\n    source '../..'\r\n}\r\n\r\ndependencies {\r\n    implementation \"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"\r\n    testImplementation 'junit:junit:4.12'\r\n    androidTestImplementation 'com.android.support.test:runner:1.0.2'\r\n    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'\r\n    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'\r\n    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'\r\n    implementation 'io.moquette:moquette-broker:0.12'\r\n}\r\n\r\nconfigurations.all {\r\n    resolutionStrategy.eachDependency { DependencyResolveDetails details ->\r\n        def requested = details.requested\r\n        if (requested.group == \"com.android.support\") {\r\n            if (!requested.name.startsWith(\"multidex\")) {\r\n                details.useVersion \"27.+\"\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n### OS version (e.g. `uname -a`)\r\n\r\nAndroid"},"comment":{"url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/comments/471373707","html_url":"https://github.com/chkr1011/MQTTnet/issues/571#issuecomment-471373707","issue_url":"https://api.github.com/repos/chkr1011/MQTTnet/issues/571","id":471373707,"node_id":"MDEyOklzc3VlQ29tbWVudDQ3MTM3MzcwNw==","user":{"login":"bangonkali","id":539946,"node_id":"MDQ6VXNlcjUzOTk0Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/539946?v=4","gravatar_id":"","url":"https://api.github.com/users/bangonkali","html_url":"https://github.com/bangonkali","followers_url":"https://api.github.com/users/bangonkali/followers","following_url":"https://api.github.com/users/bangonkali/following{/other_user}","gists_url":"https://api.github.com/users/bangonkali/gists{/gist_id}","starred_url":"https://api.github.com/users/bangonkali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bangonkali/subscriptions","organizations_url":"https://api.github.com/users/bangonkali/orgs","repos_url":"https://api.github.com/users/bangonkali/repos","events_url":"https://api.github.com/users/bangonkali/events{/privacy}","received_events_url":"https://api.github.com/users/bangonkali/received_events","type":"User","site_admin":false},"created_at":"2019-03-11T01:08:27Z","updated_at":"2019-03-11T01:08:27Z","author_association":"NONE","body":"Seems like the cause could be https://developer.android.com/reference/java/util/Optional not being supported on API level 23 which is the Device I'm currently testing with. Will update as soon as I test with a more recent device."}}
{"actor":{"display_login":"bangonkali"}}