Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova build problems after import google play service

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)
like image 268
matheus.rocha89 Avatar asked Jan 10 '23 12:01

matheus.rocha89


2 Answers

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:

  1. First copy the whole google-play-services_lib folder from ANDROID_SDK_PATH\extras\google\google_play_services\libproject\ to your project root directory.(i.e. platform/android)
  2. copy build.xml, local.properties & project.properties files from your project_root_folder/Cordova lib folder to google-play-services_lib folder.
  3. Change the project.properties file's project target to the right target (i.e. android 19).
  4. 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

  5. Goto the google-play-services folder in your project and run :

    android update project -p . (don't forget dot)

  6. Then run following commands:

    ant debug

    ant release

  7. If you get any error then first run 'ant clean debug' then follow step 6.

  8. Now you can run cordova build android OR if you are using ionic then ionic build android.

like image 79
Aks Avatar answered Feb 05 '23 04:02

Aks


remove com.google.playservices plugin and add the plugin via this command cordova plugin add https://github.com/MobileChromeApps/google-play-services.git

like image 36
vipin Avatar answered Feb 05 '23 03:02

vipin