mapiacompany / capacitor-codepush

Capacitor plugin for CodePush
http://appcenter.ms
Other
151 stars 65 forks source link

Default `www` is hardcoded and required #33

Closed rlmestre closed 3 years ago

rlmestre commented 3 years ago

Description

When building with Angular/Ionic/Capacitor for Android, the final assets output is located in ./android/app/src/main/assets/public. The path used in the AppCenter CLI updateContentsPath flag, or -c is apparently relevant to the checks performed internally (or maybe used to name the resulting zip file.) Therefore, executing appcenter codepush release -a "whatever" -c "./android/app/src/main/assets/public" prevents the update files from being found. If you move the files to a www folder (or rename public -> www, it works.

tl;dr www is hardcoded. If the resulting extracted dir is based on the zip filename, that should be used, or otherwise expose a config.

mittermayr commented 3 years ago

I tried fixing the www issue in various ways on my app here, but all failed. Last resort was to fork the repo, replace all instances that were accessing the www or /www folder with public and the app still runs, but nothing has changed it seems.

So the issue remains: once the app is killed and restarted, we're back with the original version, not the update. It does not ask for another update then, so it's registered as properly installed, just not loaded up when the app is freshly started.

I feel like this would be a super simple fix in the right place, but I wasn't able to find it. Again, forking this repo and trying to modify the www to public in the iOS Plugin sources didn't seem to work for me :/

Clovel commented 3 years ago

We got to the point where Android Studio logs show

Sending plugin error: {"save":false,"callbackId":"55766507","pluginId":"CodePush","methodName":"preInstall","success":false,"error":{"message":"Could not get the package start page"}}
[CodePush] Preinstall failure. Could not get the package start page. StackTrace: Error: Could not get the package start page

I feel like this is directly related to the issue you are discussing. Not being able to find the start page could be caused by hardcoded paths.

FYI, I have ./android/app/src/main/assets/public as the path for appcenter codepush release commands too. The application runs fine, but when applying updates we get the above logs.

Clovel commented 3 years ago

Ok, so I fixed it by replacing the "www/" instances by "public/". This is logical as Cordova used to generate "www/" directories (IIRC) whereas Capacitor generates "public/" directories.

I'll submit a MR later today.

mittermayr commented 3 years ago

So, @Clovel can you confirm the updates actually stick after app restarts? I thought I had fixed it on iOS by renaming www/ to public/ pretty much anywhere I could find it (manual edits, not bulk-replace) — this made the updates work (download and apply), but after app restarts, it simply featured the original version again.

Clovel commented 3 years ago

I confirmed it is working for Android. I'm currently battling with my Xcode installation to test this on my iPhone. I'll keep you posted.

You can take look @ my MR if you want : https://github.com/mapiacompany/capacitor-codepush/pull/35. Feedback is appreciated.

Clovel commented 3 years ago

So, after testing on iOS, I get an exception when (or after ?) applying the update. Here are some of the logs I got before the exception.

Logs

⚡️  [log] - [CodePush] Installing update
⚡️  To Native ->  Filesystem stat 73249589
⚡️  To Native ->  Http request 73249590
ERROR MESSAGE:  {"errorMessage":"The file “unzipped” couldn’t be opened because there is no such file.","message":"The file “unzipped” couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file “unzipped” couldn’t be opened because there is no such file.","message":"The file “unzipped” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem mkdir 73249591
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem getUri 73249592
⚡️  TO JS {"uri":"file:\/\/\/var\/mobile\/Containers\/Data\/Application\/<applicationID>\/Documents\/codepush\/download\/unzipped\/"}
⚡️  To Native ->  CodePush unzip 73249593
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem stat 73249594
ERROR MESSAGE:  {"errorMessage":"The file “hotcodepush.json” couldn’t be opened because there is no such file.","message":"The file “hotcodepush.json” couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file “hotcodepush.json” couldn’t be opened because there is no such file.","message":"The file “hotcodepush.json” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem stat 73249595
ERROR MESSAGE:  {"errorMessage":"The file “versions” couldn’t be opened because there is no such file.","message":"The file “versions” couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file “versions” couldn’t be opened because there is no such file.","message":"The file “versions” couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem mkdir 73249596
⚡️  TO JS undefined
⚡️  To Native ->  Filesystem stat 73249597
ERROR MESSAGE:  {"errorMessage":"The file <versionHash> couldn’t be opened because there is no such file.","message":"The file <versionHash> couldn’t be opened because there is no such file."}
⚡️  [error] - {"errorMessage":"The file <versionHash> couldn’t be opened because there is no such file.","message":"The file <versionHash> couldn’t be opened because there is no such file."}
⚡️  To Native ->  Filesystem copy 73249598
⚡️  TO JS undefined
⚡️  [log] - [CodePush] Applying full update
⚡️  To Native ->  CodePush getPublicKey 73249599
2021-06-16 21:34:16.762908+0200 App[15993:5039757] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x195fae5b4 0x1aaa2d7a8 0x196020a80 0x19602cad8 0x195e9b360 0x195e8dc80 0x10090f160 0x100b2cd28 0x100b21c54 0x100e10064 0x100e11d90 0x100e19ea0 0x100e1acc4 0x100e27a00 0x1e19ca7a4 0x1e19d174c)
libc++abi: terminating with uncaught exception of type NSException
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
(lldb) 
Clovel commented 3 years ago

I strongly believe that this is caused by the getPublicKey call that returns null if no public key has been given.

The plugin should be compatible with no signing. The android side works like that.

@mittermayr perhaps you could try my fixes with a private/public key.

Clovel commented 3 years ago

I fixed this (https://github.com/mapiacompany/capacitor-codepush/issues/33#issuecomment-864928539) problem. MR coming soon.

Thus, I can confirm that the CodePush updates do in fact stick.

alexcroox commented 3 years ago

@Clovel thank you so much for pushing this lib forward!

lincolnthree commented 3 years ago

Just for anyone else who finds this who already worked around the issue with a bit of scripting...

You can get appcenter to bundle things correctly by creating a temporary folder with 'www' as the "leaf node" containing the built app/index.html and assets.

This folder will now need to be called 'public'.

/temp-dir/www -> /temp-dir/public

Then point the appcenter-cli to this folder using -c (or) --update-contents-path.