Open jfoclpf opened 3 years ago
ok, I will take a look, because hooks nowadays are better dealt with from cordova
Please guide me here for the PR, because I know a lot of hooks for cordova, but I'm not that versed in iOS, since all the hooks I created are for android cordova projects.
For now it's clear we have to add in plugin.xml
, line 45 to <platform name="ios">
the following extra line:
<hook type="after_plugin_install" src="scripts/after_plugin_install_ios.js" />
I can write that script after_plugin_install_ios.js
in nodeJS, no problem here, but what exactly shall it run?
pod update
Just that? I'm not that versed in ios, thus I am a bit lost here. Please guide me here for the PR
Now that I think about it, this is a project level action, not a plugin level one. You do pod install only after you add a platform not after plugin install so this hook might fail in certain weird scenarios where plugin was installed first. This hook is supposed to sit in the config.xml of a project rather than the plugin.xml of plugin.
Thanks anyways for trying. Please close this issue unless you can think of some other way around it, which covers all scenarios.
I perfectly understand your point, though I have a question:
when I do cordova build ios
everything runs smoothly, that is, the build succeeds and I have a lot of plugins. But after installing this plugin, when I run again cordova build ios
the build fails. Thus there is something in this plugin that is breaking the cordova build.
Now that I think about it, this is a project level action, not a plugin level one. You do pod install only after you add a platform
I think the plugin.xml
may also accept a hook after_platform_add
, but I'm not fully sure, I need to test
@ChrisTomAlx I was checking again and yes, we can have other common hooks in plugin.xml
.
More important even that after_platform_add
we can have a hook before_compile
or before_build
. That is ok and it works. If you see the example given in docs, it's also clear that you can have common hook in plugin.xml
. We can have a hook after_platform_add
that runs pod install
and another hook before_compile
(build=prepare && compile) that runs pod update
Though I can't make it work. When I run
cordova platform add ios
cd platforms/ios
pod install
cd ../..
cordova build ios
the build fails:
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution [CP]\ Copy\ Pods\ Resources /Users/user926670/Library/Developer/Xcode/DerivedData/Denúncia_Estacionamento-cakwmvmhffwxigdavpvkssbcuvdh/Build/Intermediates.noindex/Denúncia\ Estacionamento.build/Debug-iphonesimulator/Denúncia\ Estacionamento.build/Script-B51B0A288F175CA4B58F4A1F.sh
(1 failure)
I can only make it work via Xcode when I open xcworkspace
If I remove this plugin the cordova build ios
succeeds.
@ChrisTomAlx I was checking again and yes, we can have other common hooks in plugin.xml. More important even that after_platform_add we can have a hook before_compile or before_build. That is ok and it works. If you see the example given in docs, it's also clear that you can have common hook in plugin.xml. We can have a hook after_platform_add that runs pod install and another hook before_compile (build=prepare && compile) that runs pod update
I am a little worried about doing it this way because I haven't seen any of the plugins use hooks for pod install. There might be some scenario that I am overlooking. It seems a bit hacky to me. I don't think it should be part of the plugin to be honest.
BUILD FAILED The following build commands failed: PhaseScriptExecution [CP]\ Copy\ Pods\ Resources /Users/user926670/Library/Developer/Xcode/DerivedData/Denúncia_Estacionamento-cakwmvmhffwxigdavpvkssbcuvdh/Build/Intermediates.noindex/Denúncia\ Estacionamento.build/Debug-iphonesimulator/Denúncia\ Estacionamento.build/Script-B51B0A288F175CA4B58F4A1F.sh (1 failure)
I am not entirely sure what this issue is. Were you getting the same error with the ml-text plugin as well ? If you haven't tried it yet, please check if that works, its a similar plugin to this, but it uses slightly different dependencies which all were updated recently.
$ cordova plugin add cordova-plugin-ml-text --verbose
No scripts found for hook "before_plugin_add".
No version specified for cordova-plugin-ml-text, retrieving version from config.xml
No version for cordova-plugin-ml-text saved in config.xml or package.json
Attempting to use npm info for cordova-plugin-ml-text to choose a compatible release
Ignoring invalid version in cordova-plugin-ml-text cordovaDependencies: cordova-android (must be a single version <= latest or an upper bound)
Ignoring invalid version in cordova-plugin-ml-text cordovaDependencies: cordova-ios (must be a single version <= latest or an upper bound)
Ignoring cordova-plugin-ml-text cordovaDependencies entry because it did not contain any valid plugin version entries
Calling plugman.fetch on plugin "cordova-plugin-ml-text"
fetch: Installing cordova-plugin-ml-text to /Users/user926670/dev/form-for-parking-violation
Running command: npm install cordova-plugin-ml-text --save-dev
Command finished with error code 0: npm install,cordova-plugin-ml-text,--save-dev
Copying plugin "/Users/user926670/dev/form-for-parking-violation/node_modules/cordova-plugin-ml-text" => "/Users/user926670/dev/form-for-parking-violation/plugins/cordova-plugin-ml-text"
Calling plugman.install on plugin "/Users/user926670/dev/form-for-parking-violation/plugins/cordova-plugin-ml-text" for platform "ios
Installing "cordova-plugin-ml-text" for ios
Finding scripts for "before_plugin_install" hook from plugin cordova-plugin-ml-text on ios platform only.
No scripts found for hook "before_plugin_install".
Install start for "cordova-plugin-ml-text" on ios.
Platform API successfully found in: /Users/user926670/dev/form-for-parking-violation/platforms/ios/cordova/Api.js
Beginning processing of action stack for ios project...
Action stack processing complete.
pods.json found in platforms/ios
Podfile found in platforms/ios
Adding pods since the plugin contained <podspecs>
Set pods.json for `declarations` - `use_frameworks!`
Added declaration line for `use_frameworks!`
Set pods.json for `sources` - `https://github.com/CocoaPods/Specs.git`
Added source line for `https://github.com/CocoaPods/Specs.git`
Set pods.json for `libraries` - `MLKitTextRecognition`
Added pod line for `MLKitTextRecognition`
Wrote to pods.json.
Wrote to Podfile.
Running `pod install` (to install plugins)
Running command: pod --version
Command finished with error code 0: pod --version
Running command: pod install --verbose
==== pod install start ====
Preparing
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-Denúncia Estacionamento`: (``)
Finding Podfile changes
A MLKitTextRecognition
Resolving dependencies of `Podfile`
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only perfomed in repo update
Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`
$ /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git -- cocoapods
Cloning into 'cocoapods'...
I waited several minutes and nothing
Try doing this command manually?
/usr/local/bin/git clone https://github.com/CocoaPods/Specs.git -- cocoapods
It worked, it takes ages but it works and cordova plugin add cordova-plugin-ml-text --verbose
is not that verbose
But that doesn't matter because the problem is the same, after adding this plugin cordova build ios
fails. When I remove the plugin, it succeeds.
Even better, the log file of cordova build ios
: log.txt
** BUILD FAILED **
The following build commands failed:
Ld /Users/user926670/dev/form-for-parking-violation/platforms/ios/build/emulator/Denúncia\ Estacionamento.app/Denúncia\ Estacionamento normal
(1 failure)
I have no Apple device. But when I open in XCode it builds just fine. But when I use the CLI from cordova it fails.
Same issue i faced, dont have ios device.
cordova 9.0.0 ios 5.1.1
Working:
cordova build ios --buildFlag="-UseModernBuildSystem=0"
Failing;
corodova build ios
What is the exact command you are using ? Did you try this ?
No, because I have no Apple device. I can use only for now emulators
Same issue i faced, dont have ios device.
cordova 9.0.0 ios 5.1.1
Working:
cordova build ios --buildFlag="-UseModernBuildSystem=0"
- building for emulator using xcode
Failing;
corodova build ios
- archive / build for any arm device
The command cordova build ios --buildFlag="-UseModernBuildSystem=0"
did not work either.
I also tried cordova build ios --emulator --buildFlag="-UseModernBuildSystem=0"
and it didn't work. When I remove this plugin, it works.
Cordova info on my side:
Cordova Packages:
cli: 10.0.0
common: 4.0.2
create: 3.0.0
lib: 10.0.0
common: 4.0.2
fetch: 3.0.0
serve: 4.0.0
Project Installed Platforms:
ios: 6.1.1
Project Installed Plugins:
cordova-pdf-generator: 2.1.1
cordova-plugin-app-version: 0.1.12
cordova-plugin-camera: 5.0.1
cordova-plugin-compat: 1.2.0
cordova-plugin-device: 2.0.3
cordova-plugin-email-composer: 0.9.2
cordova-plugin-file: 7.0.0-dev
cordova-plugin-geolocation: 4.1.0
cordova-plugin-inappbrowser: 4.1.0
cordova-plugin-is-debug: 1.0.0
cordova-plugin-mobile-ocr: 3.1.2
cordova-plugin-network-information: 3.0.0-dev
cordova-plugin-screen-orientation: 3.0.2
cordova-plugin-simple-image-resizer: 0.1.1
cordova-plugin-splashscreen: 6.0.0
cordova-plugin-statusbar: 2.4.3
cordova-plugin-whitelist: 1.3.4
Environment:
OS: macOS Catalina 10.15.7 (19H114) (darwin 19.6.0) x64
Node: v12.16.2
npm: 6.14.4
ios Environment:
xcodebuild:
Xcode 12.3
Build version 12C33
Project Setting Files:
config.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.form.parking.violation" version="2.6.7" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Denúncia Estacionamento</name>
<description>
Envio de queixa de estacionamento ilegal a autoridade competente
</description>
<author email="joao.pimentel.ferreira@gmail.com" href="https://www.joaopimentel.com/">
João Pimentel Ferreira
</author>
<content src="index.html"/>
<icon height="512" src="res/icon/universal/icon4_512x512_playstore.png" width="512"/>
<icon density="xhdpi" height="196" src="res/icon/universal/icon4_XHDPI_196x196_320dpi.png" width="196"/>
<icon density="xxxhdpi" height="192" src="res/icon/universal/icon4_XXXHDPI_192x192_640dpi.png" width="192"/>
<icon density="xxhdpi" height="144" src="res/icon/universal/icon4_XXHDPI_144x144_480dpi.png" width="144"/>
<icon density="hdpi" height="72" src="res/icon/universal/icon4_HDPI_72x72_240dpi.png" width="72"/>
<icon density="mdpi" height="48" src="res/icon/universal/icon4_MDPI_48x48_160dpi.png" width="48"/>
<access origin="*"/>
<allow-navigation href="*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<preference name="windows-target-version" value="10.0"/>
<preference name="windows-phone-target-version" value="10.0"/>
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle"/>
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets"/>
<preference name="StatusBarOverlaysWebView" value="false"/>
<preference name="StatusBarBackgroundColor" value="#FFFFFF"/>
<preference name="StatusBarStyle" value="blacktranslucent"/>
<hook src="hooks/importNpmPackages.js" type="before_prepare"/>
<hook src="hooks/copyCredentials.js" type="before_prepare"/>
<hook src="hooks/convertHbsToHtml.js" type="after_prepare"/>
<hook src="hooks/minifyFiles.js" type="after_prepare"/>
<platform name="android">
<preference name="android-minSdkVersion" value="22"/>
<preference name="android-targetSdkVersion" value="29"/>
<preference name="AndroidPersistentFileLocation" value="Compatibility"/>
<allow-intent href="market:*"/>
<icon height="512" src="res/icon/android/512.png" width="512"/>
<icon density="xhdpi" height="192" src="res/icon/android/192.png" width="192"/>
<icon density="xxxhdpi" height="192" src="res/icon/android/192.png" width="192"/>
<icon density="xxhdpi" height="144" src="res/icon/android/144.png" width="144"/>
<icon density="hdpi" height="72" src="res/icon/android/72.png" width="72"/>
<icon density="mdpi" height="48" src="res/icon/android/48.png" width="48"/>
<splash density="hdpi" src="res/screen/android/screen-hdpi-portrait.png"/>
<splash density="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png"/>
<splash density="ldpi" src="res/screen/android/screen-ldpi-portrait.png"/>
<splash density="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png"/>
<splash density="mdpi" src="res/screen/android/screen-mdpi-portrait.png"/>
<splash density="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png"/>
<splash density="xhdpi" src="res/screen/android/screen-xhdpi-portrait.png"/>
<splash density="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
</widget>
package.json:
--- Start of Cordova JSON Snippet ---
{
"plugins": {
"cordova-plugin-geolocation": {
"GPS_REQUIRED": "true"
},
"cordova-plugin-email-composer": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-screen-orientation": {},
"cordova-plugin-device": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-compat": {},
"cordova-pdf-generator": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-is-debug": {},
"cordova-plugin-app-version": {},
"cordova-plugin-camera": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
},
"cordova-plugin-simple-image-resizer": {
"ANDROID_EXIFINTERFACES_VERSION": "27.+"
},
"cordova-plugin-file": {},
"cordova-plugin-network-information": {},
"cordova-plugin-mobile-ocr": {}
},
"platforms": [
"browser",
"android"
]
}
--- End of Cordova JSON Snippet ---
Why don't you automate the setup after installing this plugin on iOS with a plugin hook? https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/#plugin-hooks-pluginxml