ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

no longer works with Cordova-IOS 4.5.5 ? #197

Closed wf9a5m75 closed 5 years ago

wf9a5m75 commented 5 years ago

Masashi, I actually have problems the other way around. This plugin works OK with Cordova-IOS 5.0.0 and no longer works with Cordova-IOS 4.5.5. I know it sounds strange...

See this recently closed issue for reference where bumping Cordova-IOS version to v 5.0.0 helped: https://github.com/ionic-team/ionic-native-google-maps/issues/189

Originally posted by @battika in https://github.com/ionic-team/ionic-native-google-maps/issues/196#issuecomment-480165609

wf9a5m75 commented 5 years ago

Um, as far as I test, no problem.

Screen Shot 2019-04-04 at 11 52 20 PM Screen Shot 2019-04-04 at 11 52 46 PM
wf9a5m75 commented 5 years ago

Thanks for testing, let me create a test project and see where it fails.

_Originally posted by @battika in https://github.com/ionic-team/ionic-native-google-maps/issues/196#issuecomment-480168753

battika commented 5 years ago

Hello Masashi,

After 12 hours of work I sort of managed to reliably reproduce the issue. I was using my minimal Ionic project with the bare minimum of Cordova plugins that Ionic uses plus the latest master version of this plugin:

cordova-plugin-device 2.0.2 "Device"
cordova-plugin-googlemaps 2.5.3 "cordova-plugin-googlemaps"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.0.1 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"

Here is how you can reproduce it:

  1. Clone my repo using the command git clone https://github.com/battika/ionic-gmaps-test.git
  2. Edit config.xml and package.json files to supply the API keys
  3. Run npm install to install all dependencies (should add 1010 packages)
  4. Run ionic cordova prepare ios to prepare cordova-ios platform - this will install version 4.5.5 as default
  5. Compile and run the application using the command npm run iphone7 I created as a shortcut for running the app in local debug mode using IPhone7 emulator. Or just use the regular ionic cordova run ios command...
  6. Once the emulator starts up two things can happen. It either works or it immediately quits as soon as the create() method is called. It usually works fine for the first time.
  7. I suppose it works so now you need to remove/re-add the IOS platform using the ionic cordova platform rm ios and ionic cordova platform add ios command
  8. Attempt to start the application for the second time. It usually fails to start for me, immediately quits when I call the create() method.

I was trying to find out what is causing the issue, as nothing really changes between the two attempts. I was using the diff utility to find the differences and here is the only obvious difference I spotted.

Between the working and the failing attempts the order of the Cordova plugins are different. It can be seen in the Cordova-generated plugins/ios.json, platforms/ios/ios.json, platforms/ios/www/cordova_plugins.js and platforms/ios/platform_www/cordova_plugins.js files.

The most obvious difference can be spotted in the plugins/ios.json file:

Working scenario:

{
  "prepare_queue": {
    "installed": [],
    "uninstalled": []
  },
  "config_munge": {
    "files": {}
  },
  "installed_plugins": {
    "cordova-plugin-whitelist": {
      "PACKAGE_NAME": "com.ionicgmapstest"
    },
    "cordova-plugin-device": {
      "PACKAGE_NAME": "com.ionicgmapstest"
    },
    "cordova-plugin-splashscreen": {
      "PACKAGE_NAME": "com.ionicgmapstest"
    },
    "cordova-plugin-ionic-webview": {
      "PACKAGE_NAME": "com.ionicgmapstest"
    },
    "cordova-plugin-ionic-keyboard": {
      "PACKAGE_NAME": "com.ionicgmapstest"
    },
    "cordova-plugin-googlemaps": {
      "API_KEY_FOR_IOS": "<IOS_API_KEY>",
      "LOCATION_WHEN_IN_USE_DESCRIPTION": "This app wants to get your location while this app runs only.",
      "LOCATION_ALWAYS_USAGE_DESCRIPTION": "This app wants to get your location always, even this app runs in background.",
      "PACKAGE_NAME": "com.ionicgmapstest"
    }
  },
  "dependent_plugins": {}
}

Failing scenario:

{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {}
},
"installed_plugins": {
"cordova-plugin-device": {
"PACKAGE_NAME": "com.ionicgmapstest"
},
"cordova-plugin-googlemaps": {
"API_KEY_FOR_IOS": "<IOS_API_KEY>",
"LOCATION_WHEN_IN_USE_DESCRIPTION": "This app wants to get your location while this app runs only.",
"LOCATION_ALWAYS_USAGE_DESCRIPTION": "This app wants to get your location always, even this app runs in background.",
"PACKAGE_NAME": "com.ionicgmapstest"
},
"cordova-plugin-ionic-keyboard": {
"PACKAGE_NAME": "com.ionicgmapstest"
},
"cordova-plugin-ionic-webview": {
"PACKAGE_NAME": "com.ionicgmapstest"
},
"cordova-plugin-splashscreen": {
"PACKAGE_NAME": "com.ionicgmapstest"
},
"cordova-plugin-whitelist": {
"PACKAGE_NAME": "com.ionicgmapstest"
}
},
"dependent_plugins": {}
}

You can see this plugin is the last one listed in the working scenario while it is in the middle in the failing scenario.

Now, if you run ionic cordova rm ios and ionic cordova add ios@5.0.0 to use the latest version of cordova-ios it works fine regardless of the position of this plugin. For reference here is the ios.json file that cordova-ios v5.0.0 generates

ios.json generated by Cordova-ios@5.0.0

{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {}
},
"installed_plugins": {
"cordova-plugin-device": {
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
},
"cordova-plugin-googlemaps": {
"API_KEY_FOR_IOS": "<IOS_API_KEY>",
"LOCATION_WHEN_IN_USE_DESCRIPTION": "This app wants to get your location while this app runs only.",
"LOCATION_ALWAYS_USAGE_DESCRIPTION": "This app wants to get your location always, even this app runs in background.",
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
},
"cordova-plugin-ionic-keyboard": {
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
},
"cordova-plugin-ionic-webview": {
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
},
"cordova-plugin-splashscreen": {
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
},
"cordova-plugin-whitelist": {
"PACKAGE_NAME": "$(PRODUCT_BUNDLE_IDENTIFIER)"
}
},
"dependent_plugins": {}
}

Hope I am correct regarding the order of the plugins and not side tracking the investigation with it, this was the only obvious difference that the diff utility provided.

Thank you in advance and please let me know if any questions.

wf9a5m75 commented 5 years ago

Thank you for investing.

I have a question.

Why do you need to stay corodva-ios 4.5.5? If you install Cordova iOS 5.0, then solve is gone (regarding of your investigation). If it is so, is it the problem of Cordova side, isn't it?

battika commented 5 years ago

I understand where you are coming from. My issue is, one of my Cordova plugins does not seem to play well with cordova-ios 5.0.0. And if I look into it holistically, it is a bit concerning that seemingly the order of the plugins might break Google Maps, I am afraid something is lurking in the background that we don't know what it is and when it will surface itself. I give it a go with cordova-ios 5 and see if I can break it with the order of the plugins. However I am not sure how it works, what is the logic behind the ios.json files and the rest of the Cordova files, I guess it takes some diving into the documentation and/or code.

wf9a5m75 commented 5 years ago

I see. Okay, I will check it out later. Let me take a time.

battika commented 5 years ago

Thanks Masashi. Just tested the non-functional version from XCode and it throws the following exceptions:

2019-04-06 21:57:53.786715+0200 ionicgmapstest[51240:1252195] WARNING: Unable to find and load 'GoogleMaps.bundle' for Google Maps SDK for iOS. This may be a sign that you've forgotten to include a resources bundle in your 'Copy Bundle Resources' build phase. As this bundle contains important resources, you may encounter missing images, translations and other incorrect behavior.

2019-04-06 21:57:53.789226+0200 ionicgmapstest[51240:1252195] *** Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS requires GoogleMaps.bundle to be part of your target under 'Copy Bundle Resources''

So, it seems something is not copied over when I remove/re-add the plugin?

wf9a5m75 commented 5 years ago

Google maps cocoapod is not installed, regarding of the error message.

battika commented 5 years ago

Masashi, thanks for the hint. You are correct by the error message, it seems to be missing.. I switched to the platforms/ios directory and ran the pod update command

> pod update
Update all pods
Updating local specs repositories
  $ /Applications/CocoaPods.app/Contents/Resources/bundle/bin/git -C
  /Users/battika/.cocoapods/repos/master fetch origin --progress
  remote: Enumerating objects: 77, done.
  remote: Counting objects: 100% (77/77), done.
  remote: Compressing objects: 100% (8/8), done.
  remote: Total 106 (delta 68), reused 73 (delta 67), pack-reused 29
  Receiving objects: 100% (106/106), 10.49 KiB | 0 bytes/s, done.
  Resolving deltas: 100% (71/71), completed with 42 local objects.
  From https://github.com/CocoaPods/Specs
     1ad12e5..3aa5753  master     -> origin/master
  $ /Applications/CocoaPods.app/Contents/Resources/bundle/bin/git -C
  /Users/battika/.cocoapods/repos/master rev-parse --abbrev-ref HEAD
  master
  $ /Applications/CocoaPods.app/Contents/Resources/bundle/bin/git -C
  /Users/battika/.cocoapods/repos/master reset --hard origin/master
  HEAD is now at 3aa5753 [Add] WSBox 0.4.9

CocoaPods 1.7.0.beta.3 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.7.0.beta.3

Analyzing dependencies
Downloading dependencies
Using GoogleMaps (2.7.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

...and the issue is gone. I have not idea why pod installation is not being taken care of Cordova at times.

Do you think it would be possible to put some guard rails around it and when the SDK is not present the plugin would bail out gracefully as opposed to a crash?

wf9a5m75 commented 5 years ago

Do you think it would be possible to put some guard rails around it and when the SDK is not present the plugin would bail out gracefully as opposed to a crash?

Unfortunately, no. Cocoapod installation is the role of cordova framework itself. I hope Cordova team solves this problem.