简体   繁体   中英

Gmapsfx Integration not working properly in android app Build using Gluon-mobile

Am new to Android Development using Gluon-mobile.
I have been trying to Integrate Google MapView with my Android Application , So I have used this GMapsFX Api to buid a Mapview.
My problem is that the App runs smoother on Desktop ,But When Deploying it on a Android Device the App exits.

Here's build.gradle file for this Project

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.gluonapplication.Sample'

 dependencies {
compile 'com.gluonhq:charm:4.1.0'
 androidRuntime 'org.sqldroid:sqldroid:1.0.3'
 compileNoRetrolambda 'com.jfoenix:jfoenix:1.0.0'

 compile 'com.lynden:GMapsFX:2.11.0'
 }

 jfxmobile {
downConfig {
    version = '3.2.4'
    // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
    plugins 'display', 'lifecycle', 'local-notifications', 'runtime-args', 'statusbar', 'storage'
}
android {
    manifest = 'src/android/AndroidManifest.xml'
}

}


here's the FXML file that has the MapView

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

<?import com.lynden.gmapsfx.GoogleMapView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>

<VBox alignment="CENTER" prefHeight="566.0" prefWidth="353.0" spacing="10" stylesheets="@Maps.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gluonapplication.views.MapController">
<children>

   <Label fx:id="header" layoutX="120.0" layoutY="14.0" text="the Sacred Groves" />
 <GoogleMapView fx:id="MapView" layoutX="4.0" layoutY="62.0" prefHeight="525.0" prefWidth="353.0">
     <children>
        <TextField prefHeight="25.0" prefWidth="173.0" promptText="Enter a Location!" />
     </children></GoogleMapView>

  </children>
 </VBox>


Here's the Main Class that creates the Scene.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
  */
   package com.gluonapplication;

   import javafx.application.Application;
   import javafx.fxml.FXMLLoader;
   import javafx.scene.Scene;
   import javafx.scene.layout.VBox;
   import javafx.stage.Stage;

   /**
     *
     * @author Guru
     */
    public class Sample extends Application{


public static void main(String args[])
{
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception 
{

    FXMLLoader loader=new FXMLLoader(getClass().getResource("MapsView.fxml"));
VBox box=loader.load();
Scene scene=new Scene(box);
primaryStage.setScene(scene);
primaryStage.show();

}

}


Here's the Controller class for the above fxml

/*
 * To change this license header, choose License Headers in Project Properties.
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
   */
 package com.gluonapplication.views;

 import com.gluonapplication.scenes.Backup;
 import com.gluonapplication.scenes.SceneController;
 import com.lynden.gmapsfx.*;
 import com.lynden.gmapsfx.javascript.object.*;
 import com.lynden.gmapsfx.service.directions.*;
 import java.net.URL;
 import java.util.List;
 import java.util.ResourceBundle;
 import javafx.collections.FXCollections;
 import javafx.fxml.*;


 /**
   *
  * @author Guru
  */
  public class MapController  implements Initializable,   MapComponentInitializedListener, DirectionsServiceCallback,SceneController {
   GoogleMap map;
   Backup backup=null;
    protected DirectionsService directionsService;
protected DirectionsPane directionsPane;
   @FXML
protected GoogleMapView MapView;
   @Override


public void initialize(URL location, ResourceBundle resources)
{
            MapView.addMapInializedListener(this);
            }



public void refresh()
{
    MapView.relocate(10.876224, 77.021764);
}
@Override
public void mapInitialized() {
   MapOptions options = new MapOptions();

    options.center(new LatLong(10.876224, 77.021764))
            .zoomControl(true)
            .zoom(12)
            .overviewMapControl(false)
            .mapType(MapTypeIdEnum.ROADMAP);

     map = MapView.createMap(options);

    directionsService = new DirectionsService();
    directionsPane = MapView.getDirec();


}

@Override
public void directionsReceived(DirectionsResult dr, DirectionStatus ds) 
{
}

@Override
public void setParentScene(Backup backup) {
   this.backup=backup;
}

}


Thanks in Advance !
Help to solve this Problem Everything seems fine to Me,But the App gets exits on starting itself.
But works Fine in Desktop.
I have run adb logcat -v threadtime and got this output on cmd

        04-07 22:07:25.029 31214 31214 W System.err: java.lang.reflect.InvocationTargetException
    04-07 22:07:25.030 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.030 31214 31214 W System.err:    at javafxports.android.FXDalvikEntity.onGlobalLayout(FXDalvikEntity.java:389)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1996)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6050)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer.doCallbacks(Choreographer.java:672)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer.doFrame(Choreographer.java:608)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Handler.handleCallback(Handler.java:742)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.os.Looper.loop(Looper.java:154)
    04-07 22:07:25.030 31214 31214 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:5469)
    04-07 22:07:25.030 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.030 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    04-07 22:07:25.030 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    04-07 22:07:25.030 31214 31214 W System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double javafx.scene.Scene.getHeight()' on a null object reference
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.adjustSize(TextFieldSkinAndroid.java:111)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.lambda$showSoftwareKeyboard$643(TextFieldSkinAndroid.java:107)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.access$lambda$2(TextFieldSkinAndroid.java)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid$$Lambda$3.accept(Unknown Source)
    04-07 22:07:25.031 31214 31214 W System.err:    at com.sun.glass.ui.android.DalvikInput.keyboardSize(DalvikInput.java:72)
    04-07 22:07:25.031 31214 31214 W System.err:    ... 17 more
    04-07 22:07:25.103 31214 31214 W System.err: java.lang.reflect.InvocationTargetException
    04-07 22:07:25.104 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.104 31214 31214 W System.err:    at javafxports.android.FXDalvikEntity.onGlobalLayout(FXDalvikEntity.java:389)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1996)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6050)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer.doCallbacks(Choreographer.java:672)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer.doFrame(Choreographer.java:608)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Handler.handleCallback(Handler.java:742)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.os.Looper.loop(Looper.java:154)
    04-07 22:07:25.104 31214 31214 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:5469)
    04-07 22:07:25.104 31214 31214 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-07 22:07:25.104 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    04-07 22:07:25.104 31214 31214 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    04-07 22:07:25.105 31214 31214 W System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double javafx.scene.Scene.getHeight()' on a null object reference
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.adjustSize(TextFieldSkinAndroid.java:111)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.lambda$showSoftwareKeyboard$643(TextFieldSkinAndroid.java:107)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid.access$lambda$2(TextFieldSkinAndroid.java)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.javafx.scene.control.skin.TextFieldSkinAndroid$$Lambda$3.accept(Unknown Source)
    04-07 22:07:25.105 31214 31214 W System.err:    at com.sun.glass.ui.android.DalvikInput.keyboardSize(DalvikInput.java:72)
    04-07 22:07:25.105 31214 31214 W System.err:    ... 17 more
    04-07 22:07:25.110 31214 31572 E libEGL  : validate_display:255 error 3008 (EGL_BAD_DISPLAY)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: Process: com.gluonapplication, PID: 31214
    04-07 22:07:25.150 31214 31255 E AndroidRuntime: java.lang.UnsupportedOperationException: Not supported yet.
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.WebPage.executeScript(WebPage.java:152)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine.executeScript(WebEngine.java:860)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript(JavaFxWebEngine.java:42)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView.initialiseScript(GoogleMapView.java:253)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView.access$000(GoogleMapView.java:47)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView$1.changed(GoogleMapView.java:224)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.lynden.gmapsfx.GoogleMapView$1.changed(GoogleMapView.java:221)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:176)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.updateState(WebEngine.java:1023)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1134)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$LoadWorker.access$1000(WebEngine.java:1016)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at javafx.scene.web.WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1003)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.WebPage.fireLoadEvent(WebPage.java:251)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.webkit.NativeWebView$1.run(NativeWebView.java:100)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at java.security.AccessController.doPrivileged(AccessController.java:52)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
    04-07 22:07:25.150 31214 31255 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:818)
    04-07 22:07:25.154 31214 31255 E MQSEventManagerDelegate: failed to get MQSService.

As you can check in the stacktrace, this call:

com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript()

is not supported by JavaFXPorts: the library GMapsFX makes use of a WebView control, and while this control is supported, the use of Javascript is not.

Actually, the WebView control in mobile has a different implementation than its JavaFX version one, as it uses the native implementation (android or iOS webKit).

Therefore, Javascript and other features (like history browsing) included in the JavaFX WebView, are not available on mobile.

As a possible alternative to GMapsFX, you can have a look at Gluon Maps , an open source library that runs on a JavaFX container, without a WebView.

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