Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Migrator put registerPlugin before super.onCreate #5828

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ export async function migrateCommand(config: Config): Promise<void> {
});

// remove init
await runTask('Migrating MainActivity by removing init().', () => {
return removeOldInitAndroid(config);
await runTask('Migrating MainActivity', () => {
return migrateMainActivity(config);
});

rimraf.sync(join(config.android.appDirAbs, 'build'));
Expand Down Expand Up @@ -813,7 +813,7 @@ async function podfileAssertDeploymentTarget(filename: string) {
writeFileSync(filename, replaced, 'utf-8');
}

async function removeOldInitAndroid(config: Config) {
async function migrateMainActivity(config: Config) {
const xmlData = await readXML(
join(config.android.srcMainDirAbs, 'AndroidManifest.xml'),
);
Expand Down Expand Up @@ -879,12 +879,35 @@ async function removeOldInitAndroid(config: Config) {

if (data) {
const bindex = data.indexOf('this.init(savedInstanceState');
if (bindex == -1) return;
const eindex = data.indexOf('}});', bindex) + 4;
if (bindex !== -1) {
const eindex = data.indexOf('}});', bindex) + 4;

data = data.replace(data.substring(bindex, eindex), '');
data = data.replace(data.substring(bindex, eindex), '');

data = data.replace('// Initializes the Bridge', '');
data = data.replace('// Initializes the Bridge', '');
}

const rindex = data.indexOf('registerPlugin');
if (rindex !== -1) {
if (data.indexOf('super.onCreate(savedInstanceState);') < rindex) {
data = data.replace(
'super.onCreate(savedInstanceState);\n ',
'',
);
const eindex = data.lastIndexOf('.class);') + 8;
data = data.replace(
data.substring(bindex, eindex),
`${data.substring(
bindex,
eindex,
)}\n super.onCreate(savedInstanceState);`,
);
}
}

if (bindex == -1 && rindex == -1) {
return;
}

writeFileSync(mainActivityClassFilePath, data);
}
Expand Down