1+ import org.apache.tools.ant.filters.ReplaceTokens
2+
13plugins {
24 id ' com.android.application'
35 id ' com.google.gms.google-services'
@@ -10,35 +12,57 @@ android {
1012
1113tasks. register(' conanProfile' , Copy ) {
1214 from " conanprofile.txt"
13- into " build/"
15+ into project. layout. buildDirectory
16+ filter(ReplaceTokens , tokens : [" NDK_PATH" : android. ndkDirectory. toString()])
17+ }
1418
15- doLast {
16- def file = file(" build/conanprofile.txt" )
17- def content = file. text
18- content = content. replace(" <NDK_PATH>" , android. ndkDirectory. toString())
19- file. write(content)
19+ abstract class ConanInstallTask extends Exec {
20+ @Input
21+ abstract Property<String > getArch ()
22+
23+ // Cannot read project.layout.buildDirectory when configuration-cache is enabled
24+ @Input
25+ abstract Property<String > getArchBuildDirPath ()
26+
27+ @OutputDirectory
28+ final Provider<Directory > outputDirectory = archBuildDirPath.map { new File (it ) }
29+
30+ @Override
31+ protected void exec () {
32+ commandLine(
33+ " conan" , " install" , " ." ,
34+ " --output-folder=" + archBuildDirPath. get(),
35+ " --build=missing" ,
36+ " --profile:host=build/conanprofile.txt" ,
37+ " -s" , " arch=" + arch. get(),
38+ " -s" , " build_type=Release" ,
39+ " -s" , " &:build_type=RelWithDebInfo" ,
40+ " -s" , " odrcore/*:build_type=RelWithDebInfo" ,
41+ )
42+ super . exec()
2043 }
2144}
2245
23- tasks. register(' conanInstall' ) {
24- dependsOn(tasks. named(" conanProfile" ))
25- doFirst {
26- [" armv7" , " armv8" , " x86" , " x86_64" ]. each { String arch ->
27- exec {
28- commandLine(
29- " conan" , " install" , " ." ,
30- " --output-folder=build/conan/" + arch,
31- " --build=missing" ,
32- " --profile:host=build/conanprofile.txt" ,
33- " -s" , " arch=" + arch,
34- " -s" , " build_type=Release" ,
35- " -s" , " &:build_type=RelWithDebInfo" ,
36- " -s" , " odrcore/*:build_type=RelWithDebInfo" ,
37- )
38- }
46+ [" armv8" , " armv7" , " x86" , " x86_64" ]. each { architecture ->
47+ tasks. register(' conanInstall-' + architecture, ConanInstallTask ) {
48+ setArch(architecture)
49+ setArchBuildDirPath(new File (project. layout. buildDirectory. get(). toString(), ' conan/' + architecture). absolutePath)
50+ dependsOn(tasks. named(" conanProfile" ))
51+
52+ // Execute at least one conanInstall before running all three others in parallel.
53+ // Some issue with conan's local cache
54+ // @TODO: isolate and report to conan-client bugtracker
55+ if (architecture != " armv8" ) {
56+ dependsOn(tasks. named(" conanInstall-armv8" ))
3957 }
4058 }
4159}
60+ tasks. register(" conanInstall" ) {
61+ [" armv7" , " armv8" , " x86" , " x86_64" ]. each { arch ->
62+ dependsOn tasks. named(' conanInstall-' + arch)
63+ }
64+ }
65+
4266tasks. named(" preBuild" ). configure { preBuildTask ->
4367 preBuildTask. dependsOn(tasks. named(" conanInstall" ))
4468}
@@ -176,7 +200,8 @@ dependencies {
176200// Without removing .cxx dir on cleanup, double gradle clean is erroring out.
177201// Before removing this workaround, check if "./gradlew assembleDebug; ./gradlew clean; ./gradlew clean" works
178202tasks. named(" clean" ) {
203+ def dotCxxDir = layout. projectDirectory. dir(" .cxx" )
179204 doFirst {
180- delete getLayout() . getProjectDirectory() . dir( " .cxx " )
205+ delete dotCxxDir
181206 }
182207}
0 commit comments