Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to @nativescript/core 7 #248

Open
limux82 opened this issue Aug 31, 2020 · 7 comments
Open

Upgrade to @nativescript/core 7 #248

limux82 opened this issue Aug 31, 2020 · 7 comments

Comments

@limux82
Copy link

limux82 commented Aug 31, 2020

Trying with @nativescript/core 7 (7.0.0-rc.57), version of this plugin 4.5.0 I see this error in compilation due to changes in namespace in @nativescript/core

ERROR in ../node_modules/nativescript-camera/camera.js
Module not found: Error: Can't resolve 'tns-core-modules/image-asset/image-asset' in '/node_modules/nativescript-camera'
@ ../node_modules/nativescript-camera/camera.js 4:23-74
@ ./app/core/services/camera.service.ts
@ ./app/shared/components/navigation-menu/navigation-menu.component.ts
@ ./app/shared/shared.module.ts
@ ./app/app.module.ts
@ ./main.ts

ERROR in ../node_modules/nativescript-camera/camera.js
Module not found: Error: Can't resolve 'tns-core-modules/trace/trace' in '/node_modules/nativescript-camera'
@ ../node_modules/nativescript-camera/camera.js 5:12-51
@ ./app/core/services/camera.service.ts
@ ./app/shared/components/navigation-menu/navigation-menu.component.ts
@ ./app/shared/shared.module.ts
@ ./app/app.module.ts
@ ./main.ts

@martijnvanschie
Copy link

martijnvanschie commented Sep 4, 2020

After some digging i found that you need to use another package.

Marketplace
NPM

I used the command npm i --save @nativescript/camera to get the right package and after some small refactoring it now works again.

Changed
import * as camera from "nativescript-camera";

To
import { isAvailable, requestCameraPermissions, takePicture } from '@nativescript/camera';

And updated some method calls in the code.

It's a bit unclear even from this page but it seams like there are a few different versions of this plugin around and you need to get the right one.

@limux82
Copy link
Author

limux82 commented Sep 4, 2020

Thanks I found it

@oneWaveAdrian
Copy link

oneWaveAdrian commented Sep 21, 2020

@martijnvanschie How did you use the function call? My app won't work anymore even with the @nativescript/camera package after upgrading.

I get this error message back when firing the takePicture() method
JS: error: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

This is the function I'm using up until now:

[...]
import * as camera from "@nativescript/camera";
[...]
camera
        .requestPermissions()
        .then(() => {
          camera
            .takePicture({
              keepAspectRatio: true,
              saveToGallery: false,
              height: 140,
            })
            .then((imageAsset) => {
              this.imgData.pictureFromCamera = imageAsset;
              ImageSource.fromAsset(imageAsset).then((source) => {
                this.imgData.base64image = source.toBase64String(
                  "jpeg",
                  80
                );
              });
            })
            .catch((e) => {
              console.log("error:", e);
            });
        })
        .catch((e) => {
[...]

Apparently the error is thrown in line 47 of camera.android.js

tempPictureUri = FileProviderPackageName.FileProvider.getUriForFile(core_1.Application.android.context, core_1.Application.android.nativeApp.getPackageName() + ".provider", nativeFile);

@martijnvanschie
Copy link

Have not seen that issue. I do import the camera different and perform the premissions and actual capture seperate.

Import

import { isAvailable, requestCameraPermissions, takePicture } from '@nativescript/camera';

Permissions

  ngOnInit(): void {
    if (isAvailable()) {
      requestCameraPermissions()
        .then(
          fulfilled => {
            console.log('requestCameraPermissions fulfilled.');
          },
          rejected => {
            this.showWarningMessage('No camera permissions set.');
          }
        )
    } else {
      this.showWarningMessage('No camera detected of available.');
    }
  }

Capture

  capture(): void {
    const image = this.faceImage.nativeElement as Image;
    var options = { width: 300, height: 300, keepAspectRatio: true, saveToGallery: false };

    takePicture(options)
      .then(imageAsset => {
        image.src = imageAsset;
        this.capturedImage = imageAsset;
        this.isCaptured = true;
      }).catch(function (err) {
        console.log("Error -> " + err.message);
      });
  }

Hope this helps a bit.

@oneWaveAdrian
Copy link

Well except for the altered import statement this is not new code, it worked before untouched. So it has to correlate to NS7.. thanks @martijnvanschie I'll fiddle round with it a bit more, hopefully will find a solution to this...

@oneWaveAdrian
Copy link

oneWaveAdrian commented Sep 24, 2020

Nobody knows why this happens? This seems to be a problem that happened in prior versions?

@AlexBuitrago
Copy link

Must follow these instructions to use the camera:

@nativescript/camera

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants