您的位置:首页 > 其它

cordova二维码扫描插件phonegap-plugin-barcodescanner使用及坑点

2016-05-24 21:50 531 查看
以android平台为例,IDE使用 android-studio(因为需要引用aar文件),项目是使用 $ cordova create HelloWorld 创建的

当我们按照cordova官方说明为cordova项目添加 phonegap-plugin-barcodescanner 插件后,我们发现libs目录下多了一个 barcodescanner.aar 文件

(这是这个扫描插件的资源集,如果你很好奇的话可以改下后缀解压看看里面有什么)

1、引用 barcodescanner.aar

     打开 build.gradle 文件

    把libs目录添加为资源仓库,并引用 barcodescanner.aar (下面是build.gradle修改完成后的代码。有中文注释的两个地方就是我们要添加的内容),

    然后Rebuild我们的android项目

//添加一个本地资源仓库
repositories{
flatDir {
dirs 'libs'
}
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//引用cordova二维码扫描插件aar
compile(name:'barcodescanner', ext:'aar')
debugCompile project(path: "CordovaLib", configuration: "debug")
releaseCompile project(path: "CordovaLib", configuration: "release")
}


    Rebuild完成后进入 " android \ build \ intermediates \ exploded-aar " 文件夹就可以看到我们的android项目已经引用了 barcodescanner.aar 中的资源

2、然后就可以调用官方的说明方法进行测试了。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息