离子facebook和条形码扫描器问题

时间:2018-02-04 23:33:40

标签: android facebook ionic-framework barcode-scanner

我有facebook插件和条码扫描器的问题,首先我创建了一个单独的项目来检查facebook插件如何工作并且工作正常,但是当我将facebook插件添加到我的项目中我使用barcodescanner插件我无法运行在android中的项目,我得到以下异常:

 BUILD FAILED

Total time: 10.111 secs
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

[ERROR] An error occurred while running cordova run android (exit code 1).

2 个答案:

答案 0 :(得分:2)

步骤1:安装条形码扫描器插件:

$ ionic cordova plugin add phonegap-plugin-barcodescanner
$ npm install --save @ionic-native/barcode-scanner

第2步:安装Facebook插件:(使用下面的facebook插件版本)

ionic cordova plugin add cordova-plugin-facebook4@1.7.4 --variable APP_ID="****" --variable APP_NAME="****"
npm install --save @ionic-native/facebook

第3步:从此路径打开文件facebookconnect.xmlyourapp\platforms\android\app\src\main\res\values并在<resources></resources>

中添加两行
<resources>
  <string name="fb_app_id">***your_app_id***</string>
  <string name="fb_app_name">***your_app_name***</string>
</resources>

第4步:命令:cordova clean - 允许cordova清理您的应用

第5步:命令:cordova build - 检查cordova构建您的应用

第6步:命令:ionic cordova build android - 构建应用

答案 1 :(得分:1)

更改所需的Facebook插件版本为我解决了这个问题。

var queryCode;

app.get("/profile", function (req, res, next) {

  console.log('Request Type:', req.query.code);
  queryCode = req.query.code;
  console.log(typeof queryCode);

  res.render('pages/profile', { code: req.query.code });

  var data = {
    grant_type: "authorization_code",
    code: queryCode,
    redirect_uri: "https://mydemosampleonlywebsite.com/profile", // not real edited
    client_id: 2, // edited for security
    client_secret: "98" // edited for security
  }

  function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log('body ' + body);
    }else{
      console.log('err ' + body);
    }
  }

  var options = {
    method: 'POST',
    url: 'https://api.line.me/oauth2/v2.1/token',
    headers:{
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: JSON.stringify(data)
  }

  request.post(options, callback);

  res.end();

});