@@ -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" ;
1110
@@ -123,55 +122,58 @@ 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- ) ;
137- const sharedLibraries = targets . filter (
138- ( target ) => target . type === "SHARED_LIBRARY" ,
139- ) ;
140- assert . equal (
141- sharedLibraries . length ,
142- 1 ,
143- "Expected exactly one shared library" ,
144- ) ;
145- const [ sharedLibrary ] = sharedLibraries ;
146- const { artifacts } = sharedLibrary ;
147- assert (
148- artifacts && artifacts . length ,
149- "Expected exactly one artifact" ,
150- ) ;
151- const [ artifact ] = artifacts ;
152- return [ triplet , path . join ( buildPath , artifact . path ) ] as const ;
153- } ) ,
154- ) ,
155- ) as Record < Triplet , string > ;
156- const androidLibsFilename = determineAndroidLibsFilename (
157- Object . values ( libraryPathByTriplet ) ,
158- ) ;
159- const androidLibsOutputPath = path . resolve ( outputPath , androidLibsFilename ) ;
125+ const prebuilds : Record < string , Partial < Record < Triplet , string > > > = { } ;
160126
161- await oraPromise (
162- createAndroidLibsDirectory ( {
163- outputPath : androidLibsOutputPath ,
164- libraryPathByTriplet,
165- autoLink,
166- } ) ,
167- {
168- text : "Assembling Android libs directory" ,
169- successText : `Android libs directory assembled into ${ chalk . dim (
170- path . relative ( process . cwd ( ) , androidLibsOutputPath ) ,
171- ) } `,
172- failText : ( { message } ) =>
173- `Failed to assemble Android libs directory: ${ message } ` ,
174- } ,
175- ) ;
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+ ) ;
133+ const sharedLibraries = targets . filter (
134+ ( target ) => target . type === "SHARED_LIBRARY" ,
135+ ) ;
136+ assert . equal (
137+ sharedLibraries . length ,
138+ 1 ,
139+ "Expected exactly one shared library" ,
140+ ) ;
141+ const [ sharedLibrary ] = sharedLibraries ;
142+ const { artifacts } = sharedLibrary ;
143+ assert ( artifacts && artifacts . length , "Expected exactly one artifact" ) ;
144+ const [ artifact ] = artifacts ;
145+ // Add prebuild entry, creating a new entry if needed
146+ if ( ! ( sharedLibrary . name in prebuilds ) ) {
147+ prebuilds [ sharedLibrary . name ] = { } ;
148+ }
149+ prebuilds [ sharedLibrary . name ] [ triplet ] = path . join (
150+ buildPath ,
151+ artifact . path ,
152+ ) ;
153+ }
154+
155+ for ( const [ libraryName , libraryPathByTriplet ] of Object . entries (
156+ prebuilds ,
157+ ) ) {
158+ const prebuildOutputPath = path . resolve (
159+ outputPath ,
160+ `${ libraryName } .android.node` ,
161+ ) ;
162+ await oraPromise (
163+ createAndroidLibsDirectory ( {
164+ outputPath : prebuildOutputPath ,
165+ libraryPathByTriplet,
166+ autoLink,
167+ } ) ,
168+ {
169+ text : `Assembling Android libs directory (${ libraryName } )` ,
170+ successText : `Android libs directory (${ libraryName } ) assembled into ${ chalk . dim (
171+ path . relative ( process . cwd ( ) , prebuildOutputPath ) ,
172+ ) } `,
173+ failText : ( { message } ) =>
174+ `Failed to assemble Android libs directory (${ libraryName } ): ${ message } ` ,
175+ } ,
176+ ) ;
177+ }
176178 } ,
177179} ;
0 commit comments