After the new update of the admob SDK now we need to import the google play service project to our projects to monetize and show ads in our apps. I am creating an app with Apache Cordova/ Phonegap and I created the android project with it and everything was fine. Then I opened my android project that cordova generated and import the google play service lib project and put all the native code I needed to show ads, then...GREAT! Works fine, tested on emulator, NICE, device, EVEN BETTER! But now when I updated my code on /www folder of cordova and try to run the command:
cordova build android
I always get a build error, so everytime I need to update my code and update the android project I need to remove all the references and codes of google play service I insert at the native android project generate by cordova, run the build command and then add everything again, this is a little bit boring, somebody have already pass through this? Somebody have a better solution? The error I got is this:
BUILD FAILED
/Users/matheus/Development/adt-bundle-mac/sdk/tools/ant/build.xml:601: Invalid file: /Users/matheus/Development/google-play-services_lib/build.xml
Total time: 1 second
Error code 1 for command: ant with args: debug,-f,/Users/matheus/Development/phonegap_projects/TabFipeFree/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /Users/matheus/Development/phonegap_projects/TabFipeFree/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
UPDATE:
You can also use this plugin OR you can add this line in your plugin.xml
to add this plugin as dependency.
<dependency id="com.google.playservices" />
Follow these steps to solve the problem:
ANDROID_SDK_PATH\extras\google\google_play_services\libproject\
to your project root directory.(i.e. platform/android)project_root_folder/Cordova
lib folder to google-play-services_lib
folder.project.properties
file's project target to the right target (i.e. android 19).Open the project.properties
from your Project Root folder and change reference 2 like this :
android.library.reference.1=CordovaLib
target=android-19
android.library.reference.2=google-play-services_lib
Goto the google-play-services
folder in your project and run :
android update project -p .
(don't forget dot)
Then run following commands:
ant debug
ant release
If you get any error then first run 'ant clean debug
' then follow step 6.
Now you can run cordova build android OR if you are using ionic then ionic build android.
remove com.google.playservices plugin and add the plugin via this command cordova plugin add https://github.com/MobileChromeApps/google-play-services.git
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With