phonegap3.4(Cordova)+BarcodeScanner

一、搭建phonegap环境

参考:http://blog.csdn.net/aaawqqq/article/details/19755179

 安装过程中遇到的问题:

1、node安装包下载错误,应该下载node-v0.10.26-x86.msi

2、ant安装时,环境变量配置错误

参考http://www.cnblogs.com/xieweiwei/p/3557280.html

3、换了一个sdk,环境变量配置错误,需要配置sdk下的这两个路径sdk\platform-tools;sdk\tools;

node的环境变量是在安装过程中自动配置。ant的环境变量需要手动配置


二、整合BarcodeScanner

参考:j夫子   http://zjfhw.iteye.com/blog/2029565

BarcodeScanner:http://phonegap.com/blog/build/barcodescanner-plugin/

BarcodeScanner详细安装步骤

(包括plugman):https://github.com/wildabeast/BarcodeScanner/tree/master/src/android

遇到问题:

1、将项目导入eclipse后,调整目录结构

参考http://blog.csdn.net/dzy19832006/article/details/24380759

当用eclipse打开的工程你会发现目录结构跟2.9.0差很多,在assets文件目录下只有个_where-is-www.txt,打开这个文件里头有说明:

  To show `assets/www` or `res/xml/config.xml`, go to:Project -> Properties -> Resource -> Resource Filters

  And delete the exclusion filter.

  按照提示打开项目->属性->资源->资源过滤器,然后删除exclusion 里的选项。

  在看目录assets目录下就有www文件夹,res下的xml也生成了config.xml。由于之前有使用ant进行项目的构建所有还有一些没有用的文件夹,模仿2.9.0的目录结构进行删除,这样一个3.4.0的eclipse工程就建立好了。


2、解决目录混乱问题时,顺便学会一个小技巧

运行项目成功以后,Cordova项目的bin中会自动生成Cordova.jar,也即我们需要的3.4.0版本的jar包。

把这个包扔到工程的libs目录下,这样就不用打开xxx-CordovaLib。


/*  下面两个步骤不需要  一开始按照j夫子的方法,没有用plugman方式安装插件,后来改用plugman安装后,项目中自动引入com.google.zxing.client.android.captureactivity.jar,不再需要引入额外的工程(LibraryProject)


3、整合过程中,不要将BarcodeScanner-master/src/android/com.google.zxing.client.android.captureactivity.jar引入到自己工程

如果用这个jar包,程序无法调用扫描功能,报错。

替代方法:将BarcodeScanner-master\src\android\LibraryProject工程导入eclipse工程中,具体步骤:

a. Add the 'LibraryProject' into Eclipse. File -> New Android Project -> create project from existing source.
b. In the new project you've just added to Eclipse go to the project properties. Select the Android section and at the bottom of the dialog check the "Is Library" checkbox.
c. In your application go into the project properties. In the Android section under library click the Add button and select the library you created in step 2.


4、编译过程中出现

Unable to execute dex: Multiple dex files define Lcom/baidu/mapapi/BMapManager异常

参考:http://blog.csdn.net/sky_monkey/article/details/14224521

工程出现该异常是因为同时引用了BarcodeScanner提供的jar和工程,出现dex文件冲突

*/


5、git安装

http://blog.csdn.net/ruanjf/article/details/7331197


6、plugman安装

npm install -g plugman


7、一开始用旧环境(升级了adt和sdk的eclipse)导入出了问题,后来还是用google提供的环境导入成功


8、j夫子(上面参考的文章的作者)没有用plugman安装插件成功

具体步骤为:https://github.com/wildabeast/BarcodeScanner/blob/master/src/android/README.md

a、Copy plugin files to "hello\plugins\com.phonegap.plugins.barcodescanner\". You can simply download from github:

git clone https://github.com/wildabeast/BarcodeScanner.git plugins\com.phonegap.plugins.barcodescanner
b、 Install the plugin (current dir. being "hello"):

plugman --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android
plugman install --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android
首先命令行进入构建好的项目目录:

上面步骤执行的命令中(

f:\> phonegap create my-app  

f:\> cd my-app  

f:\app> phonegap run android )

f:\app>路径

先执行

f:\app>git clone https://github.com/wildabeast/BarcodeScanner.git plugins\com.phonegap.plugins.barcodescanner

在同目录下执行

f:\app>plugman --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android

f:\app>plugman install --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android


9、测试代码

BarcodeScanner-master/README.md文档中例子:


cordova.plugins.barcodeScanner.scan(
      function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
   );


10、完工

测试过程中,不知道为什么需要扫描两次才能成功


三、一开始使用的google绑定好的eclipse,用着不习惯

后来还是用以前的开发环境,换了sdk和adt

adt插件下载、说明地址:

http://developer.android.com/sdk/installing/installing-adt.html

1.Start Eclipse, then select Help > Install New Software.

2.Click Add, in the top-right corner.

3.

In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:

https://dl-ssl.google.com/android/eclipse/

Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.

4.  Click  OK .

5.In the Available Software dialog, select the checkbox next to Developer Tools and click Next.

6.In the next window, you'll see a list of the tools to be downloaded. Click Next.

7.Read and accept the license agreements, then click Finish.

8.If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.

9.When the installation completes, restart Eclipse.


ps:

1、phonegap  api:http://docs.phonegap.com/en/3.4.0/index.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值