diff --git a/packages/cli-platform-android/src/config/findPackageClassName.ts b/packages/cli-platform-android/src/config/findPackageClassName.ts index 39cdd7ff0..5903efa62 100644 --- a/packages/cli-platform-android/src/config/findPackageClassName.ts +++ b/packages/cli-platform-android/src/config/findPackageClassName.ts @@ -32,11 +32,29 @@ export default function getPackageClassName(folder: string) { let files = getMainActivityFiles(folder); let packages = getClassNameMatches(files, folder); - if (!packages.length) { - files = getMainActivityFiles(folder, false); - packages = getClassNameMatches(files, folder); + if (packages && packages.length > 0 && Array.isArray(packages[0])) { + return packages[0][1]; } + /* + When module contains `expo-module.config.json` we return null + because expo modules follow other practices and don't implement + ReactPackage/TurboReactPackage directly, so it doesn't make sense + to scan and read hundreds of files to get package class name. + + Exception is `expo` package itself which contains `expo-module.config.json` + and implements `ReactPackage/TurboReactPackage`. + + Following logic is done due to performance optimization. + */ + + if (fs.existsSync(path.join(folder, '..', 'expo-module.config.json'))) { + return null; + } + + files = getMainActivityFiles(folder, false); + packages = getClassNameMatches(files, folder); + // @ts-ignore return packages.length ? packages[0][1] : null; }