@@ -21,6 +21,9 @@ In the next wizard window, select a name for your application, for example `MyCo
21
21
"Minimum SDK" with the suggested value (21 in our case), but remember the value as we are using it later in the Conan
22
22
profile at ``os.api_level` ``
23
23
24
+ In the "Build configuration language" you can choose between ``Groovy DSL (build.gradle) `` or ``Kotlin DSL (build.gradle.kts) ``
25
+ in order to use `conanInstall ` task bellow.
26
+
24
27
Select a "C++ Standard" in the next window, again, remember the choice as later we should use the same in the profile at
25
28
``compiler.cppstd ``.
26
29
@@ -80,69 +83,145 @@ open the ``build.gradle`` file in the ``My_Conan_App.app`` (Find it in the `Grad
80
83
Paste the ``task conanInstall `` contents after the ``plugins `` and before the ``android `` elements:
81
84
82
85
83
- .. code-block :: groovy
84
- :caption: build.gradle
86
+ .. tabs ::
85
87
88
+ .. code-tab :: groovy
89
+ :caption: build.gradle
86
90
87
- plugins {
88
- ...
89
- }
90
-
91
-
92
- task conanInstall {
93
- def conanExecutable = "conan" // define the path to your conan installation
94
- def buildDir = new File("app/build")
95
- buildDir.mkdirs()
96
- ["Debug", "Release"].each { String build_type ->
97
- ["armv7", "armv8", "x86", "x86_64"].each { String arch ->
98
- def cmd = conanExecutable + " install " +
99
- "../src/main/cpp --profile android -s build_type="+ build_type +" -s arch=" + arch +
100
- " --build missing -c tools.cmake.cmake_layout:build_folder_vars=['settings.arch']"
101
- print(">> ${cmd} \n")
102
-
103
- def sout = new StringBuilder(), serr = new StringBuilder()
104
- def proc = cmd.execute(null, buildDir)
105
- proc.consumeProcessOutput(sout, serr)
106
- proc.waitFor()
107
- println "$sout $serr"
108
- if (proc.exitValue() != 0) {
109
- throw new Exception("out> $sout err> $serr" + "\nCommand: ${cmd}")
110
- }
111
- }
112
- }
113
- }
114
91
115
- android {
116
- compileSdk 32
92
+ plugins {
93
+ ...
94
+ }
117
95
118
- defaultConfig {
96
+ task conanInstall {
97
+ def conanExecutable = "conan" // define the path to your conan installation
98
+ def buildDir = new File("app/build")
99
+ buildDir.mkdirs()
100
+ ["Debug", "Release"].each { String build_type ->
101
+ ["armv7", "armv8", "x86", "x86_64"].each { String arch ->
102
+ def cmd = conanExecutable + " install " +
103
+ "../src/main/cpp --profile android -s build_type="+ build_type +" -s arch=" + arch +
104
+ " --build missing -c tools.cmake.cmake_layout:build_folder_vars=['settings.arch']"
105
+ print(">> ${cmd} \n ")
106
+
107
+ def sout = new StringBuilder(), serr = new StringBuilder()
108
+ def proc = cmd.execute(null, buildDir)
109
+ proc.consumeProcessOutput(sout, serr)
110
+ proc.waitFor()
111
+ println "$sout $serr"
112
+ if (proc.exitValue() != 0) {
113
+ throw new Exception("out> $sout err> $serr" + "\n Command: ${cmd}")
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ android {
120
+ compileSdk 32
121
+
122
+ defaultConfig {
123
+
124
+ ...
125
+
126
+
127
+ .. code-tab :: kotlin
128
+ :caption: build.gradle.kts
129
+
119
130
120
- ...
131
+ plugins {
132
+ ...
133
+ }
134
+
135
+ tasks.register("conanInstall") {
136
+ val conanExecutable = "conan" // define the path to your conan installation
137
+ val buildDir = file("app/build")
138
+ buildDir.mkdirs()
139
+
140
+ val buildTypes = listOf("Debug", "Release")
141
+ val architectures = listOf("armv7", "armv8", "x86", "x86_64")
142
+
143
+ doLast {
144
+ buildTypes.forEach { buildType ->
145
+ architectures.forEach { arch ->
146
+ val cmd = "$conanExecutable install ../../src/main/cpp --profile android-studio " +
147
+ "-s build_type=$buildType -s arch=$arch --build missing " +
148
+ "-c tools.cmake.cmake_layout:build_folder_vars=['settings.arch']"
149
+
150
+ println(">> $cmd")
151
+
152
+ val proc = ProcessBuilder(cmd.split(" "))
153
+ .directory(buildDir)
154
+ .start()
155
+
156
+ val result = proc.inputStream.bufferedReader().readText()
157
+ val errors = proc.errorStream.bufferedReader().readText()
158
+
159
+ proc.waitFor()
160
+
161
+ if (proc.exitValue() != 0) {
162
+ throw Exception("Execution failed! Output: $result Error: $errors")
163
+ }
164
+ println(result)
165
+ if (errors.isNotBlank()) {
166
+ println("Errors: $errors")
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ tasks.named("preBuild").configure {
174
+ dependsOn("conanInstall")
175
+ }
176
+
177
+ android {
178
+ compileSdk 32
179
+
180
+ defaultConfig {
181
+
182
+ ...
121
183
122
184
123
185
The ``conanInstall `` task is calling :command: `conan install ` for Debug/Release and for each architecture we want to build, you
124
186
can adjust these values to match your requirements.
125
187
126
188
If we focus on the ``conan install `` task we can see:
127
189
128
- 1. We are passing a ``--profile android ``, so we need to create the proile . Go to the ``profiles `` folder in the
190
+ 1. We are passing a ``--profile android ``, so we need to create the profile . Go to the ``profiles `` folder in the
129
191
conan config home directory (check it running :command: `conan config home `) and create a file named ``android ``
130
192
with the following contents:
131
193
132
- .. code-block :: text
133
-
134
- include(default)
135
-
136
- [settings]
137
- os=Android
138
- os.api_level=21
139
- compiler=clang
140
- compiler.version=12
141
- compiler.libcxx=c++_static
142
- compiler.cppstd=14
143
-
144
- [conf]
145
- tools.android:ndk_path=/Users/luism/Library/Android/sdk/ndk/21.4.7075529/
194
+ .. tabs ::
195
+
196
+ .. code-tab :: text System NDK
197
+
198
+ include(default)
199
+
200
+ [settings]
201
+ os=Android
202
+ os.api_level=21
203
+ compiler=clang
204
+ compiler.version=12
205
+ compiler.libcxx=c++_static
206
+ compiler.cppstd=14
207
+
208
+ [conf]
209
+ tools.android:ndk_path=/opt/homebrew/share/android-ndk
210
+
211
+ .. code-tab :: text Conan NDK package
212
+
213
+ include(default)
214
+
215
+ [settings]
216
+ os=Android
217
+ os.api_level=21
218
+ compiler=clang
219
+ compiler.version=12
220
+ compiler.libcxx=c++_static
221
+ compiler.cppstd=14
222
+
223
+ [tool_requires]
224
+ *: android-ndk/r26d
146
225
147
226
148
227
You might need to modify:
@@ -272,8 +351,8 @@ If we click build and then run the application, we will see that the zlib depend
272
351
273
352
274
353
.. |zlib1.2.11 | image :: ../../../images/examples/cross_build/android/android_studio/zlib_1_2_11.png
275
- :width: 400
354
+ :width: 300
276
355
:alt: Android application showing the zlib 1.2.11
277
356
.. |zlib1.2.12 | image :: ../../../images/examples/cross_build/android/android_studio/zlib_1_2_12.jpg
278
- :width: 400
279
- :alt: Android application showing the zlib 1.2.12
357
+ :width: 300
358
+ :alt: Android application showing the zlib 1.2.12
0 commit comments