formulateco / cordova-plugin-injectview

Automatically inject Cordova platform and plugin scripts into your site. Supports Android and iOS.
Other
6 stars 7 forks source link

Thread 1: Exception: "data parameter is nil" #2

Closed Zeno97 closed 4 years ago

Zeno97 commented 4 years ago

How can i solve this? Why is happening? On row 37 Thread 1: Exception: "data parameter is nil"

schmich commented 4 years ago

This plugin generates a JSON file when you build your app that contains the list of plugin scripts your app uses. This JSON file gets loaded when your app runs, then the plugin scripts are loaded and combined into a single large script. The combined script is injected into the view which then gets evaluated by the JS engine.

It sounds like there is an issue with loading the JSON file at runtime. My guess is that the file does not exist or has some unexpected data or encoding. After you build your Cordova app, there should be a file named cordova-plugin-injectview.json somewhere under platforms/ios.

Zeno97 commented 4 years ago

Hi i'm sorry for being late.

at.gofg.sportscomputer.powermanagement 1.1.2 "PowerManagement" com.nikola-breznjak.voippush 1.0.2 "VoIPPushNotification" cordova-plugin-app-event 1.2.2 "Application Events" cordova-plugin-audioinput 1.0.2 "Audio Input" cordova-plugin-audiotoggle 1.0.3 "cordova-plugin-audiotoggle" cordova-plugin-background-mode 0.7.3 "BackgroundMode" cordova-plugin-badge 0.8.8 "Badge" cordova-plugin-battery-status 2.0.3 "Battery" cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab" cordova-plugin-camera 4.1.0 "Camera" cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-contacts 3.0.1 "Contacts" cordova-plugin-device 2.0.4-dev "Device" cordova-plugin-dialogs 2.0.3-dev "Notification" cordova-plugin-downloader 0.0.4 "Downloader" cordova-plugin-file-downloader 0.4.0 "Downloader" cordova-plugin-file-md5 0.3.3 "MD5 Checksum" cordova-plugin-file-opener2 3.0.0 "File Opener2" cordova-plugin-file-transfer 1.7.1 "File Transfer" cordova-plugin-file 6.0.2 "File" cordova-plugin-firebase 2.0.5 "Google Firebase Plugin" cordova-plugin-geolocation 4.0.2 "Geolocation" cordova-plugin-inappbrowser 4.0.1-dev "InAppBrowser" cordova-plugin-injectview 1.0.2 "InjectView" cordova-plugin-ios-camera-permissions 1.2.0 "iOS Permissions" cordova-plugin-ios-microphone-permissions 1.0.0 "iOS Permissions" cordova-plugin-iosrtc 6.0.9 "iosrtc" cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification" cordova-plugin-media-capture 3.0.3 "Capture" cordova-plugin-media 5.0.3 "Media" cordova-plugin-network-information 2.0.2 "Network Information" cordova-plugin-social-message 0.4.0 "Social Message" cordova-plugin-statusbar 2.4.3 "StatusBar" cordova-plugin-uptime 0.1.1 "Uptime" cordova-plugin-vibration 3.1.1 "Vibration" cordova-plugin-whitelist 1.3.4 "Whitelist" cordova-plugin-x-socialsharing 5.6.3 "SocialSharing" cordova-plugin-zip 3.1.0 "cordova-plugin-zip" cordova.plugins.diagnostic 6.0.2 "Diagnostic" es6-promise-plugin 4.2.2 "Promise" im.ltdev.cordova.UserAgent 1.0.1 "User-Agent" mobi.moica.whatsapp 0.0.1 "Whatsapp"

Thanks for your care. I appreciate it really much.

schmich commented 4 years ago

If the cordova-plugin-injectview.json does not exist after building your project, then your app will crash at runtime. We need to figure out why cordova-plugin-injectview.json isn't being created.

This plugin has a before_compile hook which runs scripts/before-compile.js to generate the JSON file. This should get executed any time you run cordova compile or cordova build. My guess is that the hook script is not being executed at build time.

How do you normally build your app? What commands do you run? If you run cordova build --verbose, you should see something like the following in the output:

Executing script found in plugin cordova-plugin-injectview for hook "before_compile": plugins/cordova-plugin-injectview/scripts/before-compile.js

If you don't see this in the output, then the before_compile hook script is not running.

If the hook script is running, we'll have to debug deeper to see what's happening. If you want, you can edit the plugins/cordova-plugin-injectview/scripts/before-compile.js file locally to add debug statements with console.log. This might help give insight as to where it's failing. The script performs a lot of checks and throws an error if anything seems weird, though, so I'd be surprised if it ran but didn't stop/error the build.

Zeno97 commented 4 years ago

I have resolved in the following way: Runned cordova build Converted the .xcarchive file in .ipa installed .ipa into iphone manually

The issue is when you run directly from xcode because he makes the archive and install on iphone bypassing your hooks. To resolve this you should run the hook not before compiling but at least do the same work "before_compile" in "after_platform_add" or in "after_prepare". In this way it doesn't matter if you run with xcode or you do manual archive and manual install

I have not still took a look into your code but i want to ask you is possible for you to implement this solution?

Zeno97 commented 4 years ago

I little update.

I have solved just changing "before_compile" hook in "after_prepare" into plugin.xml. You don't really need before_compile, consider to update your repository with this fix.

schmich commented 4 years ago

Great work! I did not consider that use of Cordova.

After reading the Cordova hooks guide, I think the following hooks are needed:

All of these hooks would point to the same script to recreate the JSON manifest file (cordova-plugin-injectview.json).

The after_plugin_add and after_plugin_rm hooks are needed since the user might run cordova plugin add/rm cordova-some-plugin followed immediately by cordova compile ios/android --debug --device. In this case, the after_prepare hook would never be called, and the JSON manifest would be incorrect (it would not be in sync with the plugin list).

I think you are correct, otherwise. I don't think the before_compile hook is needed. I will investigate more and create a fix for this issue.

Thanks a lot for the help! I appreciate it.

schmich commented 4 years ago

I pushed some changes to the hooks branch. Can you install the plugin from there and test it with your project?

cordova plugin add https://github.com/formulateco/cordova-plugin-injectview#hooks

I added the hooks we discussed to plugin.xml. If this works for you, I will clean up some things with the project and publish a new version.

Zeno97 commented 4 years ago

Again i had the same issue

I've done the following:

cordova platform remove ios
cordova plugin remove cordova-plugin-injectview
cordova plugin add https://github.com/formulateco/cordova-plugin-injectview#hooks
cordova platform add ios
cordova prepare

opened the ios folder with xcode setted development team in signing and capabilities runned with the play button from xcode to the device

schmich commented 4 years ago

Ugh, sorry, this whole plugin is a hack, and we're doing things that the Cordova platform never intended, so there are a lot of issues that we're now hitting. Also, I don't have my Macbook to test with at the moment, so this is a bit tough.

I've pushed another update that detects platforms better, writes the manifest to the platform and app directories, and registers with more hooks just to be sure.

Can you try it again?

cordova plugin add https://github.com/formulateco/cordova-plugin-injectview#hooks

Zeno97 commented 4 years ago

It worked!

schmich commented 4 years ago

Version 1.1.1 has been published with these fixes.

Also, this package is now being published to the NPM registry as cordova-plugin-injectview, so you can install it directly:

cordova plugin add cordova-plugin-injectview

Thanks again for the help!