Skip to content

Commit af7bd78

Browse files
committed
feat: platform version handling
1 parent bb2051a commit af7bd78

File tree

1 file changed

+159
-4
lines changed

1 file changed

+159
-4
lines changed

content/guide/platform-version-handling.md

Lines changed: 159 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,167 @@
22
title: Platform Version Handling
33
---
44

5-
There are several key things to understand about platform version handling (eg: Android, iOS, visionOS, macOS, Meta Quest, etc.) within the scope of your NativeScript project.
5+
There are several key things to understand about platform version handling within the scope of your NativeScript project. Platform versioning pertains to specific SDKs shipped with Android, iOS, visionOS, macOS, Meta Quest, etc.
66

7-
As customary with JavaScript ecosystem handling, maintaining `package.json` dependency version handling is quite familiar with JavaScript developers in general. We recommend [this article](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Client-side_tools/Package_management) as well as [our overview here](https://docs.nativescript.org/guide/development-workflow/using-packages#package-managers) if not familiar with package managers.
7+
In general, maintaining `package.json` dependency versions is often a familiar topic with JavaScript developers. We recommend [this article](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Client-side_tools/Package_management) as well as [our overview here](https://docs.nativescript.org/guide/development-workflow/using-packages#package-managers) if not familiar with JavaScript package managers.
88

9-
This focuses on a topic beyond the JavaScript ecosystem -- How you can manage platform versions in different circumstances.
9+
This document however focuses on a topic beyond the JavaScript ecosystem.
10+
11+
# How to manage platform versions
1012

1113
## Android
1214

13-
## iOS
15+
There are 2 key Android files in your project to keep an eye on with platform versioning over time:
16+
17+
1. `app.gradle`: [Gradle](https://gradle.org/) build configuration for Android which contains minimum, maximum and build-tools SDK targets.
18+
19+
We can specify target SDKs as follows:
20+
21+
```groovy
22+
android {
23+
compileSdkVersion 34
24+
buildToolsVersion "34"
25+
defaultConfig {
26+
minSdkVersion 24
27+
targetSdkVersion 34
28+
versionName = "1.0.0"
29+
versionCode = 1
30+
}
31+
}
32+
```
33+
34+
Every year, platforms often bump minimum requirements for public store deployments to be accepted which can often be seen [here for Google](https://developer.android.com/google/play/requirements/target-sdk). For example, it may be stated like this:
35+
36+
> New apps and app updates must target Android 14 (API level 34) or higher to be submitted to Google Play; except for Wear OS and Android TV apps, which must target Android 13 (API level 33) or higher.
37+
Existing apps must target Android 13 (API level 33) or higher to remain available to new users on devices running Android OS higher than your app's target API level.
38+
39+
It's good to refer to these platform docs from time to time (*email notifications are also often sent to Play Store accounts on these evolving requirements*) to ensure your app's targets keep up with store requirements.
40+
41+
2. `before-plugins.gradle`: (*optional*) Some plugins may fallback to gradle configured versions which you can define here to also help align with app build configuration targets.
42+
43+
We can specify additional gradle versions as follows:
44+
45+
```groovy
46+
ext {
47+
compileSdkVersion = 34
48+
buildToolsVersion = "34"
49+
minSdkVersion = 24
50+
targetSdkVersion = 34
51+
}
52+
```
53+
54+
### Android Version Errors with Solutions
55+
56+
#### Error Sample A
57+
58+
```bash
59+
1. Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that
60+
depend on it to compile against version 33 or later of the
61+
Android APIs.
62+
63+
:app is currently compiled against android-31.
64+
65+
Recommended action: Update this project to use a newer compileSdk
66+
of at least 33, for example 34.
67+
```
68+
69+
#### Error Solution A
70+
71+
This one is a bit more self explanatory since the error includes a recommended action. Just targeting higher sdk version would resolve this one.
72+
73+
#### Error Sample B
74+
75+
```bash
76+
platforms/android/app/build.gradle' line: 574
77+
A problem occurred configuring project ':app'.
78+
Could not find androidx.dynamicanimation:dynamicanimation:1.1.2
79+
```
80+
81+
#### Error Solution B
82+
83+
This is often a misspelled plugin name or invalid version. In this particular error, it's that 1.1.2 of that library does not exist; it's actually `1.1.0-alpha03` for example.
84+
85+
## iOS
86+
87+
There are 2 key iOS files in your project to keep an eye on with platform versioning over time:
88+
89+
- `App_Resources/iOS/build.xcconfig`: Sets minimum iOS deployment version
90+
91+
We can specify the minimum target as follows:
92+
93+
```bash
94+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
95+
```
96+
97+
Every year, platforms often bump minimum requirements for public store deployments to be accepted which can often be seen [here for Apple](https://developer.apple.com/ios/submit/). For example, the `Build with Xcode` section may often state something like this:
98+
99+
> All iOS and iPadOS apps uploaded to App Store Connect must be built with a minimum of Xcode 15 and the iOS 17 SDK. Starting April 2025, all iOS and iPadOS apps uploaded to App Store Connect must be built with the iOS 18 SDK.
100+
101+
It's good to refer to these platform docs from time to time (*email notifications are also often sent to App Store accounts on these evolving requirements*) to ensure your app's targets keep up with store requirements.
102+
103+
- `App_Resources/iOS/Podfile`: (*optional*) If your project brings in plugins that involve [Cocoapods](https://cocoapods.org/) it's a good idea to have one of these. It can help align platform version minimums to match your build.xcconfig.
104+
105+
We can make our `Podfile` match our build.xcconfig target versions as follows:
106+
107+
```ruby
108+
platform :ios, '17.0'
109+
110+
post_install do |installer|
111+
installer.pods_project.targets.each do |target|
112+
target.build_configurations.each do |config|
113+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
114+
end
115+
end
116+
end
117+
```
118+
119+
It's generally a good practice to have these match.
120+
121+
### iOS Version Errors with Solutions
122+
123+
#### iOS Version Error Sample A
124+
125+
```
126+
node_modules/@nativescript/swift-ui/platforms/ios/src/Common/View+Modifiers.swift:874:49: error: 'accessibilitySortPriority' is only available in iOS 14.0 or newer
127+
view = AnyView(view.accessibilitySortPriority(priority))
128+
129+
RichTextKit/Sources/RichTextKit/Format/RichTextFormatToolbarBase.swift:148:31: error: 'bordered' is only available in iOS 15.0 or newer
130+
.buttonStyle(.bordered)
131+
132+
RichTextKit/Sources/RichTextKit/Colors/RichTextColor+Picker.swift:175:22: error: 'foregroundStyle' is only available in iOS 17.0 or newer
133+
.foregroundStyle(foregroundColor)
134+
```
135+
136+
### iOS Version Error Solution A
137+
138+
This is related to 2 causes:
139+
140+
- A plugin in use, @nativescript/swift-ui, uses a modifier that is only available on iOS 14.0 or newer.
141+
- Another plugin or internal implementation in the project use uses Swift APIs that are only available in 15 and 17 or newer.
142+
143+
So what to do in a case like this? You have several options.
144+
145+
A. Set an `IPHONEOS_DEPLOYMENT_TARGET` in your `App_Resource/iOS/build.xcconfig` to the highest minimum version stated. In this case, it would be 17.0.
146+
147+
```
148+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
149+
```
150+
151+
B. Make a change to source code to properly wrap the implementations with [availability](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements/#Availability-Condition) decorators to ensure that platform version specific code does not cause an issue if your app is run on an older devicie. You can use [patch-package](https://www.npmjs.com/package/patch-package) to create the diff to manage custom source code changes made to plugins.
152+
153+
```
154+
var body: some View {
155+
if #available(iOS 17.0, *) {
156+
ZStack {
157+
// ... something only available on iOS 17 or newer
158+
}
159+
} else {
160+
// fallback
161+
EmptyView()
162+
}
163+
}
164+
```
165+
166+
## Other Considerations
167+
168+
It's common for NativeScript plugins to include a `platforms/{ios|android}` folder which merge various platform dependencies in with your project. These will often include Cocoapods, gradle plugins, or just platform specific code. It's possible these plugins may specify SDK's which need an update from time to time to match the store requirements mentioned above. You can contact plugin authors or become involved in open source yourself by helping keep your plugins up to date.

0 commit comments

Comments
 (0)