You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "GitToTheHub (via GitHub)" <gi...@apache.org> on 2025/03/23 11:58:27 UTC
[D] Plugin: Set minimum iOS deployment target [cordova]
GitHub user GitToTheHub created a discussion: Plugin: Set minimum iOS deployment target
Hi,
I wanted to ask, if i can set a minimum iOS deployment target needed for a plugin?
Regards,
Manuel
GitHub link: https://github.com/apache/cordova/discussions/529
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitHub user GitToTheHub added a comment to the discussion: Plugin: Set minimum iOS deployment target
Thanks. I want to just give out an error, when the user tries to use a plugin, when the ios `deployment-target` of the `config.xml` is too low, but i guess thats not possible?
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12601064
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
GitHub user breautek added a comment to the discussion: Plugin: Set minimum iOS deployment target
I think you're looking for the `deployment-target` [preference](https://cordova.apache.org/docs/en/12.x-2025.01/config_ref/index.html), which will set the deployment target (which is Apple's terminology for minimum iOS version for your app project).
```xml
<platform name="ios">
<preference name="deployment-target" value="13.0" />
</platform>
```
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12595851
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "erisu (via GitHub)" <gi...@apache.org>.
GitHub user erisu edited a comment on the discussion: Plugin: Set minimum iOS deployment target
If you simply want to terminate the build and notify the app user that their `deployment-target` is too low, you can use a hook script, as suggested by @breautek.
**Example Script:**
```javascript
const path = require('node:path');
const semver = require('semver');
const xcode = require('xcode');
const { ConfigParser } = require('cordova-common');
const CordovaPlatform = require('cordova-ios');
const MINIMUM_DEPLOYMENT_TARGET = '15.0';
module.exports = context => {
const projectRoot = context.opts.projectRoot;
const platformPath = path.join(projectRoot, 'platforms', 'ios');
const iosProject = new CordovaPlatform('ios', platformPath);
const cfg = new ConfigParser(iosProject.locations.configXml);
// Get Deployment Target from config.xml.
let deploymentTarget = cfg.getPreference('deployment-target', 'ios');
if (!deploymentTarget) {
const target = path.basename(iosProject.locations.xcodeCordovaProj);
const xcodeProject = xcode.project(iosProject.locations.pbxproj);
xcodeProject.parseSync();
// Get Deployment Target from pbxproj
deploymentTarget = xcodeProject.getBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', undefined, target);
}
if (compareDeploymentTarget(deploymentTarget)) {
throw new Error(`The project's deployment-target "${deploymentTarget}" is too low. Should be greater then ${MINIMUM_DEPLOYMENT_TARGET}`);
}
}
const compareDeploymentTarget = (current) => semver.lt(
// Converting the current deployment target to a semver format to compare with.
semver.coerce(current)?.version || '0.0.0',
semver.coerce(MINIMUM_DEPLOYMENT_TARGET)?.version
);
```
**Required NPM Packages:**
You'll need to install the following dependencies:
- `semver`
- `xcode`
- `cordova-common`
These packages are included with `cordova-ios`, but it's recommended to install them separately to avoid potential issues if `cordova-ios` updates or removes them.
Then set the script to run before the build (`before_build`).
The prepare step should have already been completed and if the user sets a `deployment-target` in their `config.xml`, it should be available in the platform's `config.xml`.
If it's missing, the script will retrieve the default value from `pbxproj`.
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12601774
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitHub user GitToTheHub added a comment to the discussion: Plugin: Set minimum iOS deployment target
Can i set this in a `plugin.xml`?
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12598061
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
GitHub user breautek added a comment to the discussion: Plugin: Set minimum iOS deployment target
You could maybe have a prepare hook to read the config.xml.
but im not sure if there is a way to get the cordova default value in the situation where the preference is not set at all. And naturally the default value can change across cordova ios versions...
This kinda brings up a good point though. Perhaps there is a need to declare "engine" compatibility for ios deployment targets/android api levels.
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12601186
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "erisu (via GitHub)" <gi...@apache.org>.
GitHub user erisu added a comment to the discussion: Plugin: Set minimum iOS deployment target
You would wrap it with the `config-file` element, targeting `config.xml`.
This injects it into the built `config.xml` file located in the iOS platform directory.
However, this sets the target for the entire application, not just a single plugin.
Also, anything written in the user's app `config.xml` will likely override plugin settings, so setting it in `plugin.xml` doesn’t guarantee it will be applied.
```xml
<platform name="ios">
<config-file target="config.xml" parent="/*">
<preference name="deployment-target" value="13.0" />
</config-file>
</platform>
```
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12598368
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitHub user GitToTheHub added a comment to the discussion: Plugin: Set minimum iOS deployment target
Hi,
thanks @erisu. I'll write it just in the readme what is the minimum iOS `deployment-target`. This is a little bit much to just check the minimum ios target and I'm honest, I don't have much experience with hooks and setting other dependencies :D.
But cool solution anyways :)
Regards,
Manuel
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12602311
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitHub user GitToTheHub added a comment to the discussion: Plugin: Set minimum iOS deployment target
Ok the only possibility would be to define a `deployment-target` in the `config.xml`by the plugin like @erisu noted and then check it by the prepare hook. But it would be really better, if a plugin could configure these requirements and cordova checks it :)
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12601263
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "erisu (via GitHub)" <gi...@apache.org>.
GitHub user erisu added a comment to the discussion: Plugin: Set minimum iOS deployment target
If you simply want to terminate the build and notify the app user that their `deployment-target` is too low, you can use a hook script, as suggested by @breautek.
**Example Script:**
```javascript
const path = require('node:path');
const semver = require('semver');
const xcode = require('xcode');
const { ConfigParser } = require('cordova-common');
const CordovaPlatform = require('cordova-ios');
const MINIMUM_DEPLOYMENT_TARGET = '15.0';
module.exports = context => {
const projectRoot = context.opts.projectRoot;
const platformPath = path.join(projectRoot, 'platforms', 'ios');
const iosProject = new CordovaPlatform('ios', platformPath);
const cfg = new ConfigParser(iosProject.locations.configXml);
let deploymentTarget = cfg.getPreference('deployment-target', 'ios');
if (!deploymentTarget) {
const target = path.basename(iosProject.locations.xcodeCordovaProj);
const xcodeProject = xcode.project(iosProject.locations.pbxproj);
xcodeProject.parseSync();
// Get Deployment Target from pbxproj
deploymentTarget = xcodeProject.getBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', undefined, target);
}
if (compareDeploymentTarget(deploymentTarget)) {
throw new Error(`The project's deployment-target "${deploymentTarget}" is too low. Should be greater then ${MINIMUM_DEPLOYMENT_TARGET}`);
}
}
const compareDeploymentTarget = (current) => semver.lt(
// Converting the current deployment target to a semver format to compare with.
semver.coerce(current)?.version || '0.0.0',
semver.coerce(MINIMUM_DEPLOYMENT_TARGET)?.version
);
```
**Required NPM Packages:**
You'll need to install the following dependencies:
- `semver`
- `xcode`
- `cordova-common`
These packages are included with `cordova-ios`, but it's recommended to install them separately to avoid potential issues if `cordova-ios` updates or removes them.
Then set the script to run before the build (`before_build`).
The prepare step should have already been completed and if the user sets a `deployment-target` in their `config.xml`, it should be available in the platform's `config.xml`.
If it's missing, the script will retrieve the default value from `pbxproj`.
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12601774
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [D] Plugin: Set minimum iOS deployment target [cordova]
Posted by "erisu (via GitHub)" <gi...@apache.org>.
GitHub user erisu edited a comment on the discussion: Plugin: Set minimum iOS deployment target
You would wrap it with the `config-file` element, targeting `config.xml`.
This injects it into the built `config.xml` file located in the iOS platform directory.
However, this sets the target for the entire application, not just a single plugin.
Also, anything written in the user's app `config.xml` will likely override plugin settings, so setting it in `plugin.xml` doesn't guarantee it will be applied.
```xml
<platform name="ios">
<config-file target="config.xml" parent="/*">
<preference name="deployment-target" value="13.0" />
</config-file>
</platform>
```
GitHub link: https://github.com/apache/cordova/discussions/529#discussioncomment-12598368
----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@cordova.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org