Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

gradle - JavaFX Android Port - Google Play Services

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:UsersMartinDocumentsNetBeansProjectsTriouildjavafxportsmpandroidAndroidManifest.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...