Cordova构建问题后导入google play服务 [英] Cordova build problems after import google play service

查看:253
本文介绍了Cordova构建问题后导入google play服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在admob SDK的新更新后,我们需要将google play服务项目导入到我们的项目中,以便在我们的应用中获利并展示广告。我创建了一个应用程序与Apache Cordova / Phonegap和我创建了Android项目与它,一切都很好。然后我打开我的Android项目cordova生成和导入谷歌播放服务lib项目,并把所有的本地代码,我需要显示广告,然后...伟大!工作正常,测试模拟器,NICE,设备,甚至更好!但现在当我更新我的代码on / www文件夹cordova并尝试运行命令:
cordova build android



我总是得到一个构建错误,所以每次我需要更新我的代码和更新Android项目我需要删除所有的参考和谷歌播放服务的代码我插入在原生android项目生成由cordova,运行build命令再添加一遍,这有点无聊,有人已经通过了这个?有人有更好的解决方案?
我得到的错误是:

  BUILD FAILED 
/用户/ matheus / Development / adt- bundle-mac / sdk / tools / ant / build.xml:601:无效的文件:/Users/matheus/Development/google-play-services_lib/build.xml

总时间:1秒
命令的错误代码1:ant with args:debug,-f,/ Users / matheus / Development / phonegap_projects / TabFipeFree / platforms / android / build.xml,-Dout.dir = ant-build,-Dgen.absolute。 dir = ant-gen
错误:/ Users / matheus / Development / phonegap_projects / TabFipeFree / platforms / android / cordova / build:命令失败,退出代码2
在ChildProcess.whenDone(/ usr / local / lib / node_modules / cordova / node_modules / cordova-lib / src / cordova / superspawn.js:131:23)
在ChildProcess.EventEmitter.emit(events.js:98:17)
at maybeClose child_process.js:753:16)
在Process.ChildProcess._handle.onexit(child_process.js:820:5)


解决方案

UPDATE:
您也可以使用插件或者您可以在 plugin.xml 中添加此行以将此插件添加为依赖关系。 / p>

 < dependency id =com.google.playservices/> 

按照以下步骤解决问题:


  1. 首先将整个google-play-services_lib文件夹从 ANDROID_SDK_PATH\extras\google\google_play_services\libproject\ 复制到您的项目根目录(即platform / android)

  2. 复制build.xml,local.properties& project.properties文件从 project_root_folder / Cordova lib文件夹更改为 google-play-services_lib 文件夹。

  3. project.properties 文件的项目目标更改为正确的目标(例如Android 19)。

  4. 从您的项目根文件夹中打开 project.properties ,并像这样更改引用2:



    android.library。参考1 = CordovaLib



    target = android-19



    android.library.reference.2 = google- play-services_lib


  5. 转到您的项目中的 google-play-services 文件夹, p>

    android更新项目-p (不要忘记点)


  6. 然后运行以下命令:



    ant debug




  7. 如果您遇到任何错误,请先执行 ant clean debug ,然后按照第6步。

    / li>
  8. 现在你可以运行cordova build android或者如果你使用离子,然后离子生成android。



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:

  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.

这篇关于Cordova构建问题后导入google play服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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