@@ -25,51 +25,148 @@ tasks.register("prepareKotlinBuildScriptModel"){
2525def projectRoot = rootProject. projectDir. absolutePath
2626def addonFile = new File (projectRoot, " addons.make" )
2727
28+ println " projectRoot = ${ projectRoot} "
29+ println " addonFile = ${ addonFile.absolutePath} "
30+
31+
2832// Get all addon paths from addons.make
33+
34+ def ofRoot = " /../../../"
35+
2936def addonPaths = []
3037if (addonFile. exists()) {
3138 addonFile. eachLine { line ->
32- def addonPath = ofRoot + " addons/" + line
33- if (new File (addonPath). exists()) {
39+ def addonRelPath = ofRoot + " /addons/" + line. trim()
40+ def addonPath = new File (projectRoot, addonRelPath). canonicalFile
41+ println " Resolved addon path: ${ addonPath} "
42+ if (addonPath. exists()) {
3443 addonPaths. add(addonPath)
44+ } else {
45+ println " Missing addon path: ${ addonPath} "
3546 }
3647 }
3748}
3849
50+ println " Checking path: ${ addonPaths} "
51+
52+
3953def addonIncludeDirs = []
54+ def addonSourceFiles = []
4055def addonLibs = []
4156
4257// Collect include directories and libraries for each addon
4358addonPaths. each { addon ->
59+ // Add addon/src
4460 def includePath = new File (addon, " src" )
4561 if (includePath. exists()) {
4662 addonIncludeDirs. add(includePath. absolutePath)
63+ includePath. eachFileRecurse { file ->
64+ if (file. name. endsWith(" .cpp" ) || file. name. endsWith(" .c" )) {
65+ println " Found C/CPP source: ${ file} "
66+ addonSourceFiles. add(file. absolutePath)
67+ }
68+ }
69+ def javaDirs = [
70+ new File (addon, " java" ),
71+ new File (addon, " kotlin" ),
72+ new File (addon, " srcJava" ),
73+ new File (addon, " src" )
74+ ]
75+ javaDirs. each { dir ->
76+ if (dir. exists()) {
77+ dir. eachFileRecurse { file ->
78+ if (file. name. endsWith(" .java" ) || file. name. endsWith(" .kt" )) {
79+ println " Found Java/Kotlin source: ${ file} "
80+ addonSourceFiles. add(file. absolutePath)
81+ }
82+ }
83+ }
84+ }
85+ }
86+ // Add libs/*/include/
87+ def libsDir = new File (addon, " libs" )
88+ if (libsDir. exists()) {
89+ libsDir. eachDir { subLib ->
90+ def includeDir = new File (subLib, " include" ). canonicalFile
91+ if (includeDir. exists()) {
92+ println " Found sublib include: ${ includeDir} "
93+ addonIncludeDirs. add(includeDir. absolutePath)
94+ }
95+ }
4796 }
4897}
49-
5098// Define supported Android ABIs
5199def supportedAbis = [" arm64-v8a" , " armeabi-v7a" , " x86_64" ]
100+ def currentAbis = []
101+ if (android. defaultConfig. ndk. abiFilters != null && ! android. defaultConfig. ndk. abiFilters. isEmpty()) {
102+ currentAbis = android. defaultConfig. ndk. abiFilters. toList()
103+ } else {
104+ currentAbis = supportedAbis
105+ }
106+ println " abiFilters type: ${ android.defaultConfig.ndk.abiFilters?.getClass()} "
107+ println " abiFilters value: ${ android.defaultConfig.ndk.abiFilters} "
108+ println " currentAbis value: ${ currentAbis} "
52109
110+ def addonLibMap = [:]. withDefault { [] }
111+
112+ supportedAbis. each { abi -> addonLibMap[abi] = [] }
53113addonPaths. each { addon ->
54- supportedAbis. each { abi ->
55- def libPath = new File (addon, " libs/android/${ abi} " )
56- if (libPath. exists()) {
57- def libFiles = libPath. listFiles()?. findAll { it. name. endsWith(" .so" ) || it. name. endsWith(" .a" ) }
58- if (libFiles) {
59- addonLibs. addAll(libFiles* . absolutePath)
114+ def libsDir = new File (addon, " libs" )
115+ if (libsDir. exists() && libsDir. isDirectory()) {
116+ libsDir. eachDir { subLib ->
117+ def libRoot = new File (subLib, " lib/android" )
118+ supportedAbis. each { abi ->
119+ def archDir = new File (libRoot, abi). canonicalFile
120+ if (archDir. exists() && archDir. isDirectory()) {
121+ def libFiles = archDir. listFiles()?. findAll {
122+ it. name. endsWith(" .so" ) || it. name. endsWith(" .a" )
123+ }
124+ if (libFiles) {
125+ addonLibMap[abi]. addAll(libFiles* . absolutePath)
126+ }
127+ }
60128 }
61129 }
62130 }
63131}
64- println " Addon Libraries found: ${ addonLibs} "
132+
133+ addonPaths. each { addon ->
134+ def libsDir = new File (addon, " libs" )
135+ if (libsDir. exists() && libsDir. isDirectory()) {
136+ libsDir. eachDir { subLib ->
137+ def libRoot = new File (subLib, " lib/android" )
138+ supportedAbis. each { abi ->
139+ def archDir = new File (libRoot, abi). canonicalFile
140+ println " Checking: ${ archDir} "
141+ if (archDir. exists() && archDir. isDirectory()) {
142+ def libFiles = archDir. listFiles()?. findAll {
143+ it. name. endsWith(" .so" ) || it. name. endsWith(" .a" )
144+ }
145+ if (libFiles && ! libFiles. isEmpty()) {
146+ println " Found ${ libFiles.size()} libraries in ${ archDir} :"
147+ libFiles. each { lib -> println " - ${ lib.absolutePath} " }
148+ addonLibs. addAll(libFiles* . absolutePath)
149+ } else {
150+ println " No libs found in ${ archDir} "
151+ }
152+ }
153+ }
154+ }
155+ } else {
156+ println " No 'libs/' folder in ${ addon.name} "
157+ }
158+ }
159+ println " Addon Libraries found: [${ addonLibs} ]"
65160
66161// Convert lists to CMake arguments
67- def cmakeIncludeArgs = " -DADDON_INCLUDE_DIRS=" + addonIncludeDirs. join(" ;" )
68- def cmakeLibArgs = " -DADDON_LIBS=" + addonLibs. join(" ;" )
162+ def cmakeIncludeArgs = " -DADDON_INCLUDE_DIRS=\" " + addonIncludeDirs. join(" ;" ) + " \" "
163+ def cmakeLibArgs = " -DADDON_LIBS=\" " + addonLibs. join(" ;" ) + " \" "
164+ def cmakeSrcArgs = " -DADDON_SOURCES=" + addonSourceFiles. join(" ;" )
69165
70166println " Found addons: " + addonPaths
71167println " Include directories: " + addonIncludeDirs
72- println " Libraries: " + addonLibs
168+
169+
73170
74171android {
75172 compileSdkVersion 34
@@ -91,30 +188,27 @@ android {
91188 }
92189 }
93190 defaultConfig {
94- applicationId " cc.openframeworks.emptyExample " // IMPORTANT : THIS DEFINES THE ID OF THE APK
191+ applicationId " cc.openframeworks.androidAssimpExample " // IMPORTANT : THIS DEFINES THE ID OF THE APK
95192 minSdkVersion 24
96193 targetSdkVersion 34
97194 versionCode 12
98195 versionName ' 12.0'
99196 ndk. abiFilters ' armeabi-v7a' , ' arm64-v8a' , ' x86_64'
100197
198+ def androidSTL = " -DANDROID_STL=c++_shared"
199+ if (project. hasProperty(" OF_STATIC" ) && project. OF_STATIC . toBoolean()) {
200+ androidSTL " -DANDROID_STL=c++_static"
201+ }
202+
101203 externalNativeBuild {
102204 cmake {
103205 arguments " -DANDROID_TOOLCHAIN=clang" ,
104- " -DTARGET_OPENGLES=TRUE"
105-
106- // Use c++_static if building OpenFrameworks as a STATIC library
107- if (project. hasProperty(" OF_STATIC" ) && project. OF_STATIC . toBoolean()) {
108- arguments " -DANDROID_STL=c++_static"
109- } else {
110- arguments " -DANDROID_STL=c++_shared"
111- }
112-
113- // Enable NEON only for ARM architectures
114- if (android. defaultConfig. ndk. abiFilters. contains(" armeabi-v7a" ) || android. defaultConfig. ndk. abiFilters. contains(" arm64-v8a" )) {
115- arguments " -DANDROID_ARM_NEON=TRUE"
116- }
117-
206+ " -DTARGET_OPENGLES=TRUE" ,
207+ " -DCMAKE_VERBOSE_MAKEFILE=ON" ,
208+ cmakeIncludeArgs,
209+ cmakeLibArgs,
210+ cmakeSrcArgs,
211+ androidSTL
118212 abiFilters ' armeabi-v7a' , ' arm64-v8a' , ' x86_64'
119213 version ' 3.22.1'
120214 }
@@ -173,7 +267,6 @@ android {
173267 cmake {
174268 path " ${ CMAKELIST_PATH} /CMakeLists.txt"
175269 }
176-
177270 }
178271 compileOptions {
179272 sourceCompatibility JavaVersion . VERSION_1_8
0 commit comments