Javafx与Android - Api [英] Javafx with Android - Api

查看:256
本文介绍了Javafx与Android - Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在JavaFx项目中使用Android特定的代码。我在JavaFX上编写了一个小型游戏,当我使用JavaFX-Ports时,我可以在Android Handy上运行这个游戏。现在我想展示一些广告,为此我必须使用FXActivity作为上下文。



我导入了FXActivity

  import javafxports.android.FXActivity; 

然后我得到这个错误:

  D:\Martin\Programmieren\fx to android\Trio\src\main\java\\\
et \hagh\Main.java:18:
错误:包javafxports.android不存在
import javafxports.android.FXActivity;
^
1错误
:compileJava失败

jfxdvk.jar和android.jar(从Android-SDK)到我的依赖关系,现在我的build.gradle文件如下所示:

  buildscript {
repositories {
jcenter()
}

依赖关系{
classpath'org.javafxports:jfxmobile-plugin:1.0.0-b9 '
}
}

应用插件:'org.javafxports.jfxmobile'

mainClassName ='net.hagh.Main'

dependencies {
编译文件(D:/ Programmieren / fx到android / dalvik -sdk / rt / lib / ext / jfxdvk.jar,C:/ Users / Martin / AppData / Local / )
}
$ b存储库{
jcenter()
}
code>

与以前相同的错误...



我错了什么我该如何做对吗?我搜索了很长时间的解决方案,但有很多不同的教程,我认为其中大部分都已过时。
有人可以给我一个正确的build.gradle文件吗?



我发现这个例子: https://bitbucket.org/javafxports/samples/src/56e2050ef9e1/HelloPlatform/?at=default ,我认为这是正确的做法。但我不明白如何使用这种方式的FXActivity



编辑:我打开了一个新的 question for this



NetBeans的Gluon插件和HelloPlatform示例帮助了我,但现在我想使用Google-Play-Services来显示增加。
添加到我的build.gradle文件中:

 存储库{
def androidHome = System.getenv (ANDROID_HOME)
maven {url$ androidHome / extras / android / m2repository /}
maven {url$ androidHome / extras / google / m2repository /}
}

依赖关系{
编译fileTree(包括:['* .jar'],dir:'libs')
编译'com.google.android.gms:play-services-ads :7.5.0'
}

在我的AndroidManifest.xml中添加: p>

 < meta-data android:name =com.google.android.gms.versionandroid:value =@ integer / google_play_services_version/> 

当我尝试构建apk文件时,他们会得到我的下一个错误

 :processAndroidResources UP-TO-DATE 
C:\Users\Martin\Documents\NetBeansProjects\Trio\build \javafxports\tmp\android\AndroidManifest.xml:27:错误:错误:找不到与给定名称相匹配的资源(值为'@ integer / google_play_services_version')。

:processAndroidAndroidResources FAILED

我搜索了一下,发现我应该包括google-play-services_lib,但我不知道如何。它是我第一次使用gradle

解决方案

对于初学者,您不需要添加这些依赖关系:jfxmobile插件可以做到这一点已经为你。

您可以看看Gloun 插件,用JavaFXPorts创建一个新的JavaFX项目。



现在,在这个新项目中,如果你想添加一些Android代码,你必须添加它在Android / Java包上。



正如您已经指出的那样,开始的一种方法是遵循 HelloPlatform 。它包含一个 PlatformService 来为你加载这个类,这取决于你正在运行的平台。感谢这一点,如果你使用的是Android系统,你可以加载 AndroidPlatformProvider 。因此,无论平台如何,您都必须提供您想要从主类调用的方法,并在每个平台上实现它们(至少使用虚拟内容)。



你也可以看看这个问题,因为它使用android代码提供完整的解决方案。


I'm trying to use Android specific code in a JavaFx Project. I wrote a litte game on JavaFX and when I use JavaFX-Ports I can run this Game on my Android Handy. Now I want to display some ads and for this I have to use the FXActivity as a context.

I imported the FXActivity

import javafxports.android.FXActivity;

Then I get this Error:

D:\Martin\Programmieren\fx to android\Trio\src\main\java\net   \hagh\Main.java:18:
error: package javafxports.android does not exist
import javafxports.android.FXActivity;
                      ^
1 error
:compileJava FAILED

Now I added the jfxdvk.jar and android.jar (from Android-SDK) to my dependencies and now my build.gradle file looks like:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b9'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'net.hagh.Main'

dependencies {
    compile files("D:/Programmieren/fx to android/dalvik-sdk/rt/lib/ext/jfxdvk.jar", "C:/Users/Martin/AppData/Local/Android/android-sdk/platforms/android-22/android.jar")
}

repositories {
    jcenter()
}

The same error as before...

What did I wrong and how can I do it right? I searched long for a solution but there are so many different tutorials and I think most of them are outdated. Can someone give me a correct build.gradle file?

I found this example: https://bitbucket.org/javafxports/samples/src/56e2050ef9e1/HelloPlatform/?at=default and I think this is the right way to do it. But I dont understand how to use the FXActivity in this way

Edit: I opened a new question for this

The Gluon plugin for NetBeans and the HelloPlatform example helped me but now I want to use the Google-Play-Services to show adds. In added this to my build.gradle file:

repositories {
    def androidHome = System.getenv("ANDROID_HOME")
    maven { url "$androidHome/extras/android/m2repository/" }
    maven { url "$androidHome/extras/google/m2repository/"}
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.google.android.gms:play-services-ads:7.5.0'
}

And in my AndroidManifest.xml I added:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

And their I get my next error when I try to build the apk-file

:processAndroidResources UP-TO-DATE
C:\Users\Martin\Documents\NetBeansProjects\Trio\build\javafxports\tmp\android\AndroidManifest.xml:27: error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

:processAndroidAndroidResources FAILED

I searched a bit and I found that I should include the google-play-services_lib but I dont know how. Its my first time working with gradle

解决方案

For starters, you don't need to add those dependencies: the jfxmobile plugin does it already for you.

You may have a look at the Gloun plugin for NetBeans, to create a new JavaFX project with JavaFXPorts.

Now, in this new project, if you want to add some Android code, you have to add it on the Android/Java package.

One way to start is, as you have already pointed out, by following HelloPlatform. It includes a PlatformService to load for you the class depending on the platform you are running. Thanks to that, you can load AndroidPlatformProvider if you are on Android. So you would have to provide the methods you want to call from your main class, regardless the platform, and implement them on each platform (at least with dummy content).

You can also have a look at this question, as it provides a full solution with android code.

这篇关于Javafx与Android - Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆