nstudio / nativescript-cardview

:diamonds: :clubs: NativeScript widget for Material Design CardView
MIT License
282 stars 51 forks source link

android.support.v7.CardView is not a function #4

Closed mikeres0 closed 8 years ago

mikeres0 commented 8 years ago

I am receiving this error when attempting to use this plugin. The error originates from line 23 of cardview.android.js. Any idea why this could be happening?

I am using the mark up provided in the readme.md, so I thought this would work straight out of he box.

bradmartin commented 8 years ago

@mikeres0 what's the error?

bradmartin commented 8 years ago

Oh sorry, the title is your error. Sorry, on phone so didn't catch that.

mikeres0 commented 8 years ago

Sorry I should have been clearer. The error I receive is TypeError: android.support.v7.widget.CardView is not a function

bradmartin commented 8 years ago

The error would seem to indicate the CardView library isn't in your project, this is something that NativeScript has issues with. I'm guess you tried it in an existing project, so you've already built the app before. For some reason NativeScript apps once built and you try to add additional libraries they don't come in like they should. There's an issue open about it, and I believe they have a fix for it coming in 1.6 or 1.7. If you try using their UI suite for nativescript on a project already built the same error will occur with the recyclerview library not pulling in correctly.

Try removing your platform and then adding the plugin prior to building the .apk the first time and the library will come in correctly.

bradmartin commented 8 years ago

Also when you do this watch your console and if you look over it closely around 20-30% or the build you should see where libraries start being added.

Its fairly early on, I think it's around the 20-30% mark, don't hold me to that number :)

mikeres0 commented 8 years ago

Yeah you're correct, I added the library in to a pre-existing app. I'll go and have a fiddle around and check back. Thanks for your quick responses @bradmartin! Couldn't have asked for better support.

bradmartin commented 8 years ago

No problem. You just caught me as I was walking up checking emails :) so good timing. Hope you get this fixed. If not, let me know and I'll check on it for you.

mikeres0 commented 8 years ago

I tried what you suggested but unfortunately it didn't work for me. It may have been an issue with what I did though...

A work around is to create a new project, npm install nativescript-cardview, tns platform add * and finally copy and paste your existing project files into the new projects directory.

bradmartin commented 8 years ago

It should work on the existing if you try:

Remove platform Add platform Add plugin Build

If that doesn't work it might be a configuration issue. It works for me when I do those steps. What CLI version of {N} do you have?

On Fri, Feb 5, 2016, 5:57 AM Mike Resoli notifications@github.com wrote:

I tried what you suggested but unfortunately it didn't work for me. It may have been an issue with what I did though...

A work around is to create a new project, npm install nativescript-cardview, tns platform add * and finally copy and paste your existing project files into the new projects directory.

— Reply to this email directly or view it on GitHub https://github.com/bradmartin/nativescript-cardview/issues/4#issuecomment-180319461 .

mikeres0 commented 8 years ago

@bradmartin Sorry for the lengthy reply time. I am using version 1.5.2 of the CLI.

bradmartin commented 8 years ago

I still can't reproduce this. Can you check what version of the Support libs you have for Android? That might be the issue, shouldn't be but possible. The latest is 23.1.1 (November 2015) - so make sure to update if you don't.

mikeres0 commented 8 years ago

23.1.1 is installed... It's puzzling me quite a bit.

bradmartin commented 8 years ago

@mikeres0 - can you check this on {N} 1.6.2 and see if the error still happens?

mikeres0 commented 8 years ago

Yeah unfortunately so On 24 Feb 2016 04:54, "Brad Martin" notifications@github.com wrote:

@mikeres0 https://github.com/mikeres0 - can you check this on {N} 1.6.2 and see if the error still happens?

— Reply to this email directly or view it on GitHub https://github.com/bradmartin/nativescript-cardview/issues/4#issuecomment-188068236 .

jangedoo commented 8 years ago

I was also facing a similar problem. I did two things at once which fixed my issue but not sure which one really fixed it.

  1. Delete the android folder inside "platforms"
  2. I think this modules should be inside node_modules directory which is at the "root" (where your main package.json file is). I was inside "app" directory when I did npm install nativescript-cardview so there was another "node_modules" folder inside "app" folder which might have been a problem for me.

Then I did tns build android.

In the console log, I could see a message "Successfully prepared plugin nativescript-cardview for android." and now its working!

I hope it helps.

bradmartin commented 8 years ago

@mikeres0 - if you're okay with it can you close this issue. I know you've had several of these crazy issues with setup/config and what @jangedoo suggested fixed the issue for him. So could you try that and see if it works fine. Just not sure what to do since I can't reproduce it with my setup.

mikeres0 commented 8 years ago

@bradmartin Yeah no problem.

nikolal commented 8 years ago

For anyone else with this issue:

1) tns platform remove android 2) uninstall the app from device 3) npm install nativescript-cardview 4) tns platform add android Then run the app and it will work...