@@ -5,7 +5,6 @@ import path from "node:path";
55import { Option , oraPromise , chalk } from "@react-native-node-api/cli-utils" ;
66import {
77 createAndroidLibsDirectory ,
8- determineAndroidLibsFilename ,
98 AndroidTriplet as Triplet ,
109} from "react-native-node-api" ;
1110import * as cmakeFileApi from "cmake-file-api" ;
@@ -123,56 +122,59 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
123122 return typeof ANDROID_HOME === "string" && fs . existsSync ( ANDROID_HOME ) ;
124123 } ,
125124 async postBuild ( { outputPath, triplets } , { autoLink, configuration } ) {
126- const libraryPathByTriplet = Object . fromEntries (
127- await Promise . all (
128- triplets . map ( async ( { triplet, buildPath } ) => {
129- assert (
130- fs . existsSync ( buildPath ) ,
131- `Expected a directory at ${ buildPath } ` ,
132- ) ;
133- const targets = await cmakeFileApi . readCurrentTargetsDeep (
134- buildPath ,
135- configuration ,
136- "2.0" ,
137- ) ;
138- const sharedLibraries = targets . filter (
139- ( target ) => target . type === "SHARED_LIBRARY" ,
140- ) ;
141- assert . equal (
142- sharedLibraries . length ,
143- 1 ,
144- "Expected exactly one shared library" ,
145- ) ;
146- const [ sharedLibrary ] = sharedLibraries ;
147- const { artifacts } = sharedLibrary ;
148- assert (
149- artifacts && artifacts . length ,
150- "Expected exactly one artifact" ,
151- ) ;
152- const [ artifact ] = artifacts ;
153- return [ triplet , path . join ( buildPath , artifact . path ) ] as const ;
154- } ) ,
155- ) ,
156- ) as Record < Triplet , string > ;
157- const androidLibsFilename = determineAndroidLibsFilename (
158- Object . values ( libraryPathByTriplet ) ,
159- ) ;
160- const androidLibsOutputPath = path . resolve ( outputPath , androidLibsFilename ) ;
125+ const prebuilds : Record < string , Partial < Record < Triplet , string > > > = { } ;
161126
162- await oraPromise (
163- createAndroidLibsDirectory ( {
164- outputPath : androidLibsOutputPath ,
165- libraryPathByTriplet,
166- autoLink,
167- } ) ,
168- {
169- text : "Assembling Android libs directory" ,
170- successText : `Android libs directory assembled into ${ chalk . dim (
171- path . relative ( process . cwd ( ) , androidLibsOutputPath ) ,
172- ) } `,
173- failText : ( { message } ) =>
174- `Failed to assemble Android libs directory: ${ message } ` ,
175- } ,
176- ) ;
127+ for ( const { triplet, buildPath } of triplets ) {
128+ assert ( fs . existsSync ( buildPath ) , `Expected a directory at ${ buildPath } ` ) ;
129+ const targets = await cmakeFileApi . readCurrentTargetsDeep (
130+ buildPath ,
131+ configuration ,
132+ "2.0" ,
133+ ) ;
134+ const sharedLibraries = targets . filter (
135+ ( target ) => target . type === "SHARED_LIBRARY" ,
136+ ) ;
137+ assert . equal (
138+ sharedLibraries . length ,
139+ 1 ,
140+ "Expected exactly one shared library" ,
141+ ) ;
142+ const [ sharedLibrary ] = sharedLibraries ;
143+ const { artifacts } = sharedLibrary ;
144+ assert ( artifacts && artifacts . length , "Expected exactly one artifact" ) ;
145+ const [ artifact ] = artifacts ;
146+ // Add prebuild entry, creating a new entry if needed
147+ if ( ! ( sharedLibrary . name in prebuilds ) ) {
148+ prebuilds [ sharedLibrary . name ] = { } ;
149+ }
150+ prebuilds [ sharedLibrary . name ] [ triplet ] = path . join (
151+ buildPath ,
152+ artifact . path ,
153+ ) ;
154+ }
155+
156+ for ( const [ libraryName , libraryPathByTriplet ] of Object . entries (
157+ prebuilds ,
158+ ) ) {
159+ const prebuildOutputPath = path . resolve (
160+ outputPath ,
161+ `${ libraryName } .android.node` ,
162+ ) ;
163+ await oraPromise (
164+ createAndroidLibsDirectory ( {
165+ outputPath : prebuildOutputPath ,
166+ libraryPathByTriplet,
167+ autoLink,
168+ } ) ,
169+ {
170+ text : `Assembling Android libs directory (${ libraryName } )` ,
171+ successText : `Android libs directory (${ libraryName } ) assembled into ${ chalk . dim (
172+ path . relative ( process . cwd ( ) , prebuildOutputPath ) ,
173+ ) } `,
174+ failText : ( { message } ) =>
175+ `Failed to assemble Android libs directory (${ libraryName } ): ${ message } ` ,
176+ } ,
177+ ) ;
178+ }
177179 } ,
178180} ;
0 commit comments