[Capacitor][Solved] Newbie questions


#1

Hi all, I’m new to the Capacitor party so I have got some newbie questions :wink:

  1. Unlike Cordova, no more config.xml, so we have to manage Info.plist and AndroidManifest.xml. Do you guys then only commit these files in your repo or do you commit the all “platforms” or do you commit nothing? What’s the general best practice there to ensure the lifecycle of the app

  2. If I want to write hooks (I know myself, at some point I gonna remove plugins and platforms and gonna add them again), is there something specific to Capacitor in order to chain them or should I take care of it by myself? I meant, with Cordova I was writing “Cordova’s hook” (https://cordova.apache.org/docs/fr/latest/guide/appdev/hooks/), is there any look a like idea with Capacitor?

  3. About the Camera, as far as I saw, no Gallery support yet. Is that something in the roadmap? Same question for supporting result of type FILE instead of Base64?

Thx in advance for any hints and congrats for the alpha release. Works fine and documentation is super easy to understand!

P.S: Asked the same questions on the slack channel


#2

Slack answer:

  1. We only change the info.plist and AndroidManifest on capacitor add platform to set the name and identifier/package name, then you manage it as you wish. Unlike Cordova, in Capacitor apps, the ios and android folders (where the native apps are), are not build artifacts, we won’t change them ever, so you have to commit them.
  2. We don’t have hooks so far, or events where to hook them, so you should run them manually for now.
  3. It has gallery support, at least on iOS, should double check Android. About FILE, probably.

#3

And I’ve got a fourth question:

  1. I tried to ran my demo with ionic serve but was unable to run neither the camera or the geolocation in a browser, face errors with both of them in my browser. If I understand the doc (https://capacitor.ionicframework.com/docs/web/) basically I have nothing to do, everything should be handled by the cli right? or do I miss something?

#4

So answer to that last one

  1. ionic serve not yet supported. first build the app and then run npx cap serve. Furthermore the following need to be added in index.html (I guess till a better solution)

    <script src='https://unpkg.com/@ionic/pwa-elements@0.0.11/dist/ionicpwaelements.js'></script>

#5

Look like I’m an infinite amount of questions :wink:

  1. What is the size (width/height) of the photo taken with Camera.getPhoto? max width/height according the device used or a defined size? These options are also in the roadmap?

#6

Answer to 5. is “open feature requests”


#7

Hi @reedrichards

Great thread.

My questions (and some answers).

  • are you getting issues opening Studio after running npx cap open android for the first time? I need to set “windowsAndroidStudioPath” to a proper location (instead of some sort of H-folder). Easy fix to put it the new config in capacitor.config.json. I bet there is some feature request to automate this using PATH?)

  • android studio is complaining “Unregistered VCS root detected”. Probably not a big deal. So I skipped it.

  • When I run, it wants me to select Android SDK first. So through Stackoverflow I found a fix : Tools -> Android -> Sync Project with Gradle Files (Android Studio 3.0.1)

-> in android studio, i see under app->java three folders, the one related to my project and two unknown com.getcapacitor.myapp (androidTest) and com.getcapacitor.myapp (test). What are those

The camera plugin worked on a Galaxy TAB A 10.1. But not on my emulator (Pixl2 with emulated camera - the camera app works).

Regads

Tom


#8

Cool post @Tommertom :thumbsup:

I didn’t faced that problem. I’m on a Mac that could be the reason why.

Agree with you safe to ignore. One the Git repo is safe, this warning will disappear. Android Studio is based on IntellIJ and that’s a typical IntellIJ information.

Didn’t had this neither but Android Studio made a lot of updates the first time I ran my test project :wink:

In Android Studio which tab did you opened? When I check my Project view it does look like the following:

Mmmmh I think you should open an issue about that one https://github.com/ionic-team/capacitor/issues


#9

Also may I ask you @Tommertom, where you able to add the iOS platform?

I’m still facing issue and can’t try iOS with capacitor

when I do

ionic start captest
cd captest/
npm install --save @capacitor/core @capacitor/cli
npx cap init captest com.something.captest
ionic build
npx cap add ios

I get

iOS found these plugins:  []
[info] No Capacitor plugins found. That's ok, you can add more plugins later by npm installing them.
X Updating iOS native dependencies: undefined
X update ios: undefined
(node:3593) UnhandledPromiseRejectionWarning: Analyzing dependencies
Fetching podspec for `CordovaPlugins` from `../../node_modules/@capacitor/cli/assets/capacitor-cordova-ios-plugins`
Fetching podspec for `CordovaPluginsResources` from `../../node_modules/@capacitor/cli/assets/capacitor-cordova-ios-plugins`
[!] Unable to find a specification for `Capacitor`

#10

Running windows 10

D:\Data\Coding Projects\ionic\capitest>npx cap add ios
D:\Data\Coding Projects\ionic\capitest\node_modules\@capacitor\cli\bin\capacitor
[error] Not running Mac OS X, can't add ios platform

Simple as that…
(there is an issue raised on their github for this)


#11

image

See under app->java

Rgds
Tom


#12

Same for me


#13

Done

Btw, I have never seen the Javascript expression const { Camera } = Plugins; before

What is the name of this kind of expression? (it’s easy to understand what it does, I just have never seen it)


#14

Me neither, never seen it :wink:

They also use the async and await functions which is quite new too I think no?


#15

Destructuring assignment.

Edit: more precisely, the assignment of { Camera } is object destructuring.


#16

Seen that one before. Actually, on Slack Matt said to use Promise pattern. Which I prefer anyway.


#17

Cool, good to know, thx


#18

Regarding the notes and questions I had above, the last open issue is now solved (see following) therefore I gonna mark this post as solved.

I wasn’t able to add the iOS platform. The problem was linked somehow to my local cocoapods which wasn’t up-to-date

pod repo update

should have fix the issue, but somehow for me it doesn’t work, this was throwing the error

[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

but I was then able to update it like following

sudo rm -fr ~/.cocoapods/repos/master
pod setup

also just to be sure I reinstalled pod again

sudo gem install cocoapods

then I was finally succesfully able to add the iOS platform

npx cap add ios

#19

hi reedrichards,
After adding the script 'https://unpkg.com/@ionic/pwa-elements@0.0.11/dist/ionicpwaelements.js, all my ionic icons show twice. Any idea?
doubleicon


#20

Someone else just reported the issue