简体   繁体   中英

using jfoenix in android

JFoenix works well on desktop applications .But when implementing this on android its getting struck (app stops working and exits prompting the dialog unfortunately apps stopped working with a report button ).

So how to Implement JFoenix in android ?


here's the build.gradle below

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.2.0'
}
 }
apply plugin :'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
    url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
   }

    mainClassName = 'com.sample.Main'

    dependencies {
compile 'com.gluonhq:charm:4.2.0'
compile 'com.jfoenix:jfoenix:1.0.0'
       //compile files('lib/jfoenix-0.0.0-SNAPSHOT-retrolambda.jar')
    }

    jfxmobile {
downConfig {
    version = '3.1.0'
    // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
    plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
    manifest = 'src/android/AndroidManifest.xml'
}
ios {
    infoPList = file('src/ios/Default-Info.plist')
    forceLinkClasses = [
            'com.gluonhq.**.*',
            'javax.annotations.**.*',
            'javax.inject.**.*',
            'javax.json.**.*',
            'org.glassfish.json.**.*'
    ]
}

}

And here's the fxml file build using JFoenix
(As you can see I have included JFXDatePicker )

<?xml version="1.0" encoding="UTF-8"?>

   <?language javascript?>
   <?import com.jfoenix.controls.JFXDatePicker?>
   <?import javafx.scene.control.Button?>
   <?import javafx.scene.control.Label?>
   <?import javafx.scene.control.ToggleButton?>
   <?import javafx.scene.control.ToggleGroup?>
   <?import javafx.scene.image.Image?>
   <?import javafx.scene.image.ImageView?>
   <?import javafx.scene.layout.AnchorPane?>

   <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="620.0" prefWidth="360.0" style="-fx-background-color: linear-gradient(#c3361d,fuchsia);" stylesheets="@Next.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.android.scheduler.Next">

     <children>
     <Label text="Now ,You can Schedule Wifi" AnchorPane.leftAnchor="70.0" />
     <ToggleButton fx:id="ON" layoutX="152.0" layoutY="68.0" mnemonicParsing="false" onAction="#ON" text="On">
  <toggleGroup>
        <ToggleGroup fx:id="select" />
     </toggleGroup>
  </ToggleButton>
  <ToggleButton fx:id="OFF" layoutX="195.0" layoutY="68.0" mnemonicParsing="false" onAction="#OFF" text="Off" toggleGroup="$select" />
  <Label layoutX="49.0" layoutY="66.0" text="Action:" />      <Label fx:id="scheduled" layoutX="76.0" layoutY="107.0" text="Choose between Any one" />
  <Label layoutX="5.0" layoutY="202.0" text="Start Time:" />
  <Label layoutX="6.0" layoutY="283.0" text="End Time :" />
  <Button defaultButton="true" layoutX="129.0" layoutY="354.0" mnemonicParsing="false" text="Schedule" textAlignment="CENTER">
      <graphic>
          <ImageView>
              <image>
                  <Image url="@reminders-24.png" />
              </image>
          </ImageView>
      </graphic>
  </Button>
  <Button layoutX="113.0" layoutY="436.0" mnemonicParsing="false" onAction="#gotoHome" text="Back to Home">
  <graphic>
      <ImageView>
         <image>
             <Image url="@home-24.png" />
         </image>
      </ImageView>
  </graphic>
  </Button>
  <Label layoutX="195.0" layoutY="247.0" text="to" />
  <Label layoutX="110.0" layoutY="155.0" text="Hours" />
  <Label layoutX="184.0" layoutY="155.0" text="Minutes" />
  <JFXDatePicker fx:id="start" defaultColor="#b2dbee" layoutX="139.0" layoutY="210.0" showTime="true" />
  <JFXDatePicker fx:id="end" defaultColor="#b2dbee" layoutX="139.0" layoutY="287.0" showTime="true" />
   </children>

   </AnchorPane>

If you check the exception (running adb logcat -v threadtime ):

02-26 19:10:40.811 27570 27595 E AndroidRuntime: java.lang.NoSuchMethodError: No direct method lambda$new$423(Ljavafx/beans/value/ObservableValue;Ljavafx/scene/paint/Paint;Ljavafx/scene/paint/Paint;)V in class Lcom/jfoenix/svg/SVGGlyph; or its super classes (declaration of 'com.jfoenix.svg.SVGGlyph' appears in /data/app/com.gluon.testjfoenix-1/base.apk)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.svg.SVGGlyph.access$lambda$0(SVGGlyph.java)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.svg.SVGGlyph$$Lambda$1.changed(Unknown Source)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:69)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.svg.SVGGlyph.setFill(SVGGlyph.java:87)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.svg.SVGGlyph.<init>(SVGGlyph.java:65)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.skins.JFXDatePickerSkin.<init>(JFXDatePickerSkin.java:77)
02-26 19:10:40.811 27570 27595 E AndroidRuntime:    at com.jfoenix.controls.JFXDatePicker.createDefaultSkin(JFXDatePicker.java:85)

the error refers to a missing method in com.jfoenix.svg.SVGGlyph .

Having a look at the source code, you will find that there is a lambda expression.

Before the jfxmobile plugin version 1.1.0, all the external jars added as dependency to a javafxports project required the use of the retrolambda plugin, so that's probably why the jfoenix project added retrolambda .

After that version, the jfxmobile plugin applies retrolambda to all the external dependencies as well, so they don't need the retrolamda plugin anymore.

But there is an issue if both the dependency and the jfxmobile plugin apply the retrolambda plugin, and this is what is exactly happening here: applying twice the retrolambda plugin fails.

There are two possible solutions:

  1. Compile jfoenix without retrolambda, and add it to the project (and create an issue for this, so the author removes it as well)

  2. Use compileNoRetrolambda 'com.jfoenix:jfoenix:1.0.0' as dependency. This will use the original dependency, which already has retrolambda applied once.

I've tried the second solution and it works perfectly fine.

As an aside, Gluon Mobile (the charm dependency in your build), also includes a DatePicker and a TimePicker following Material Design.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM