Skip to content

Commit 70d26ea

Browse files
authored
feat: platform version handling (#160)
1 parent e413c32 commit 70d26ea

File tree

2 files changed

+185
-9
lines changed

2 files changed

+185
-9
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Platform Version Handling
3+
---
4+
5+
There are several key things to understand about platform version handling within the scope of your NativeScript project. When talking about platform versions, we are referring to specific platform level SDKs shipped with Android, iOS, visionOS, macOS, Meta Quest, etc.
6+
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.
8+
9+
This document however focuses on a topic beyond the JavaScript ecosystem.
10+
11+
# How to manage platform versions
12+
13+
## Android
14+
15+
The [@nativescript/android](https://github.com/NativeScript/android) dependency is good to keep your project up to date with as it often contains system level updates and requirements.
16+
17+
Beyond that, there are 2 key Android files in your project to keep an eye on with platform versioning over time:
18+
19+
1. `app.gradle`: [Gradle](https://gradle.org/) build configuration for Android which contains minimum, maximum and build-tools SDK targets.
20+
21+
We can specify target SDKs as follows:
22+
23+
```groovy
24+
android {
25+
compileSdkVersion 34
26+
buildToolsVersion "34"
27+
defaultConfig {
28+
minSdkVersion 24
29+
targetSdkVersion 34
30+
versionName = "1.0.0"
31+
versionCode = 1
32+
}
33+
}
34+
```
35+
36+
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:
37+
38+
> 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.
39+
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.
40+
41+
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.
42+
43+
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.
44+
45+
We can specify additional gradle versions as follows:
46+
47+
```groovy
48+
ext {
49+
compileSdkVersion = 34
50+
buildToolsVersion = "34"
51+
minSdkVersion = 24
52+
targetSdkVersion = 34
53+
}
54+
```
55+
56+
### Android Version Errors with Solutions
57+
58+
#### Error Sample A
59+
60+
```bash
61+
1. Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that
62+
depend on it to compile against version 33 or later of the
63+
Android APIs.
64+
65+
:app is currently compiled against android-31.
66+
67+
Recommended action: Update this project to use a newer compileSdk
68+
of at least 33, for example 34.
69+
```
70+
71+
#### Error Solution A
72+
73+
This one is a bit more self explanatory since the error includes a recommended action. Just targeting higher sdk version would resolve this one.
74+
75+
#### Error Sample B
76+
77+
```bash
78+
platforms/android/app/build.gradle' line: 574
79+
A problem occurred configuring project ':app'.
80+
Could not find androidx.dynamicanimation:dynamicanimation:1.1.2
81+
```
82+
83+
#### Error Solution B
84+
85+
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.
86+
87+
## iOS
88+
89+
The [@nativescript/ios](https://github.com/NativeScript/ios) dependency is good to keep your project up to date with as it often contains system level updates and requirements.
90+
91+
Beyond that, there are 2 key iOS files in your project to keep an eye on with platform versioning over time:
92+
93+
- `App_Resources/iOS/build.xcconfig`: Sets minimum iOS deployment version
94+
95+
We can specify the minimum target as follows:
96+
97+
```bash
98+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
99+
```
100+
101+
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:
102+
103+
> 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.
104+
105+
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.
106+
107+
- `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.
108+
109+
We can make our `Podfile` match our build.xcconfig target versions as follows:
110+
111+
```ruby
112+
platform :ios, '17.0'
113+
114+
post_install do |installer|
115+
installer.pods_project.targets.each do |target|
116+
target.build_configurations.each do |config|
117+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
118+
end
119+
end
120+
end
121+
```
122+
123+
It's generally a good practice to have these match.
124+
125+
### iOS Version Errors with Solutions
126+
127+
#### Error Sample A
128+
129+
```
130+
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
131+
view = AnyView(view.accessibilitySortPriority(priority))
132+
133+
RichTextKit/Sources/RichTextKit/Format/RichTextFormatToolbarBase.swift:148:31: error: 'bordered' is only available in iOS 15.0 or newer
134+
.buttonStyle(.bordered)
135+
136+
RichTextKit/Sources/RichTextKit/Colors/RichTextColor+Picker.swift:175:22: error: 'foregroundStyle' is only available in iOS 17.0 or newer
137+
.foregroundStyle(foregroundColor)
138+
```
139+
140+
### Error Solution A
141+
142+
This is related to 2 causes:
143+
144+
- A plugin in use, @nativescript/swift-ui, uses a modifier that is only available on iOS 14.0 or newer.
145+
- Another plugin or internal implementation in the project use uses Swift APIs that are only available in 15 and 17 or newer.
146+
147+
So what to do in a case like this? You have several options.
148+
149+
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.
150+
151+
```
152+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
153+
```
154+
155+
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.
156+
157+
```
158+
var body: some View {
159+
if #available(iOS 17.0, *) {
160+
ZStack {
161+
// ... something only available on iOS 17 or newer
162+
}
163+
} else {
164+
// fallback
165+
EmptyView()
166+
}
167+
}
168+
```
169+
170+
## Other Considerations
171+
172+
It's common for [NativeScript plugins](https://docs.nativescript.org/plugins/) that your project may depend on 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.

content/sidebar.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,18 @@ export default [
161161
{
162162
text: 'Fundamental Concepts',
163163
items: [
164+
{
165+
text: 'Accessibility',
166+
link: '/guide/accessibility',
167+
},
164168
{
165169
text: 'Animations',
166170
link: '/guide/animations',
167171
},
172+
{
173+
text: 'Best Practices',
174+
link: '/best-practices/',
175+
},
168176
...coreSidebarItems,
169177
{
170178
text: 'Data Binding',
@@ -199,7 +207,7 @@ export default [
199207
{
200208
text: 'Styling',
201209
link: '/guide/styling',
202-
},
210+
}
203211
],
204212
},
205213
{
@@ -254,14 +262,6 @@ export default [
254262
text: 'Shared Element Transitions',
255263
link: '/guide/shared-element-transitions',
256264
},
257-
{
258-
text: 'Accessibility',
259-
link: '/guide/accessibility',
260-
},
261-
{
262-
text: 'Best Practices',
263-
link: '/best-practices/',
264-
},
265265
{
266266
text: 'Multithreading',
267267
link: '/guide/multithreading',
@@ -296,6 +296,10 @@ export default [
296296
},
297297
],
298298
},
299+
{
300+
text: 'Platform Version Handling',
301+
link: '/guide/platform-version-handling',
302+
}
299303
],
300304
},
301305
] as NSSidebarGroup[]

0 commit comments

Comments
 (0)