Skip to content

Commit c85e12e

Browse files
authored
doc: update mainTemplate.gradle (#1410)
1 parent 1c0aee7 commit c85e12e

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,83 @@ The easiest way to include `libstdc++_shared.so` in your APK is to place it in t
170170

171171
You can also include `libstdc++_shared.so` at build time by adding the following code to your [`mainTemplate.gradle` file](https://docs.unity3d.com/Manual/gradle-templates.html), and the sample project is using this method.
172172

173+
<details>
174+
175+
<summary>NDK >= 23</summary>
176+
177+
```gradle
178+
// Include libc++_shared.so
179+
task copyLibcppShared {
180+
doLast {
181+
def ndkDir = android.ndkDirectory
182+
def abiFilters = android.defaultConfig.ndk.abiFilters
183+
def destDir = file("$projectDir/src/main/jniLibs")
184+
185+
// Mapping from ABI to architecture triple (for NDK 23+)
186+
def abiToTriple = [
187+
'arm64-v8a': 'aarch64-linux-android',
188+
'armeabi-v7a': 'arm-linux-androideabi',
189+
'x86': 'i686-linux-android',
190+
'x86_64': 'x86_64-linux-android',
191+
'riscv64': 'riscv64-linux-android'
192+
]
193+
194+
// Find the prebuilt directory (usually there's only one)
195+
def prebuiltDir = null
196+
def prebuiltBase = file("$ndkDir/toolchains/llvm/prebuilt")
197+
if (prebuiltBase.exists()) {
198+
def prebuiltDirs = prebuiltBase.listFiles()?.findAll { it.isDirectory() }
199+
if (prebuiltDirs && prebuiltDirs.size() > 0) {
200+
prebuiltDir = prebuiltDirs[0]
201+
}
202+
}
203+
204+
abiFilters.each { abi ->
205+
if (prebuiltDir != null) {
206+
def triple = abiToTriple[abi]
207+
if (triple != null) {
208+
def libcppPath = file("$prebuiltDir/sysroot/usr/lib/$triple/libc++_shared.so")
209+
if (libcppPath.exists()) {
210+
def destAbiDir = file("$destDir/$abi")
211+
copy {
212+
from libcppPath
213+
into destAbiDir
214+
}
215+
}
216+
}
217+
}
218+
}
219+
}
220+
}
221+
222+
task cleanCopyLibcppShared {
223+
doLast {
224+
def destDir = file("$projectDir/src/main/jniLibs")
225+
def abiFilters = android.defaultConfig.ndk.abiFilters
226+
227+
abiFilters.each { abi ->
228+
def libcppFile = file("$destDir/$abi/libc++_shared.so")
229+
if (libcppFile.exists()) {
230+
libcppFile.delete()
231+
}
232+
}
233+
}
234+
}
235+
clean.dependsOn 'cleanCopyLibcppShared'
236+
237+
tasks.whenTaskAdded { task ->
238+
if (task.name == "mergeDebugJniLibFolders" || task.name == "mergeReleaseJniLibFolders") {
239+
task.dependsOn("copyLibcppShared")
240+
}
241+
}
242+
```
243+
244+
</details>
245+
246+
<details>
247+
248+
<summary>NDK < 23</summary>
249+
173250
```gradle
174251
// Include libc++_shared.so
175252
task copyLibcppShared(type: Copy) {
@@ -186,6 +263,8 @@ tasks.whenTaskAdded { task ->
186263
}
187264
```
188265

266+
</details>
267+
189268
## :plate_with_cutlery: Try the sample app
190269

191270
Before using the plugin in your project, it's strongly recommended that you check if sample scenes work.

0 commit comments

Comments
 (0)