Skip to content

Commit bd4e66c

Browse files
committed
RU-T46 Fixing build
1 parent fe3f24c commit bd4e66c

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

plugins/withMediaButtonModule.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/^package\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(/namespace\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(/^(package\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

Comments
 (0)