JavaFX Android Port - Google Play Services

2020-02-15 05:24发布

问题:

I have written a little game on JavaFX and ported it successfully to Android. Now I want to include some Google Ads. For this I created a PlatformService and AndroidPlatformProvider like in this example shown. I'm using the Gluon plugin for Netbeans

I 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 as a library but I dont know how. Its my first time working with gradle

In the Android SDK Manager I installed the newest Play Services and the Repository

回答1:

This is not a complete solution, but just a workaround...

You are right about the google-play-services_lib: it contains a fat jar with all the services. If you just copy this jar to your libs folder, you won't need any of the dependencies but this:

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

Now, you can build your project, but you'll still need the meta-data on the manifest file.

If you have a look at google-play-services_lib folder, you'll also find a res/values folder, with a version.xml file. There you have what you are looking for. So now you can find the value editing this file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">7571000</integer>
</resources>

and replacing the string on AndroidManifest.xml:

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

But since you will need those resources as well as the jar, I think it's a better approach copying all the res content into your android/res folder.

Now you should be able to build your apk.