@@ -478,19 +478,30 @@ const withMediaButtonModule = (config) => {
478478 // Update MainApplication.kt to register the package
479479 config = withMainApplication ( config , ( config ) => {
480480 const mainApplication = config . modResults ;
481+ const projectRoot = config . modRequest . projectRoot ;
481482
482483 // Check if MediaButtonPackage is already imported/added
483484 if ( ! mainApplication . contents . includes ( 'MediaButtonPackage' ) ) {
484- // Get the package name from the first line of the file
485- const packageMatch = mainApplication . contents . match ( / ^ p a c k a g e \s + ( [ ^ \s ] + ) / ) ;
486- const packageName = packageMatch ? packageMatch [ 1 ] : 'com.resgrid.unit' ;
485+ // Read the BASE package name from build.gradle (namespace)
486+ // This is where the native module files are actually created
487+ const buildGradlePath = path . join ( projectRoot , 'android' , 'app' , 'build.gradle' ) ;
488+ let basePackageName = 'com.resgrid.unit' ; // Default fallback
489+
490+ if ( fs . existsSync ( buildGradlePath ) ) {
491+ const buildGradleContent = fs . readFileSync ( buildGradlePath , 'utf-8' ) ;
492+ const namespaceMatch = buildGradleContent . match ( / n a m e s p a c e \s + [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / ) ;
493+ if ( namespaceMatch ) {
494+ basePackageName = namespaceMatch [ 1 ] ;
495+ }
496+ }
487497
488- // Add import statement for MediaButtonPackage after the package declaration
489- const importStatement = `import ${ packageName } .MediaButtonPackage` ;
498+ // Add import statement using the BASE package name (not the variant-specific package)
499+ // The native module files are created in the base package, not in variant packages like 'development'
500+ const importStatement = `import ${ basePackageName } .MediaButtonPackage` ;
490501 if ( ! mainApplication . contents . includes ( importStatement ) ) {
491502 // Add import after the package declaration line
492503 mainApplication . contents = mainApplication . contents . replace ( / ^ ( p a c k a g e \s + [ ^ \n ] + \n ) / , `$1${ importStatement } \n` ) ;
493- console . log ( ' [withMediaButtonModule] Added MediaButtonPackage import' ) ;
504+ console . log ( ` [withMediaButtonModule] Added MediaButtonPackage import from base package: ${ basePackageName } ` ) ;
494505 }
495506
496507 // Add the package to getPackages()
0 commit comments