Skip to content

Commit

Permalink
[tools] Update android versioning script for sdk 47 (expo#19518)
Browse files Browse the repository at this point in the history
# Why

update android versioning script for sdk 47

# How

- [android] update gradle wrapper version to 7.5.1, which aligned with react-native 0.70
- [localization] fix compileSdkVersion 33 build error
- [tools] update versioning script
  - remove `renameHermesEngine` which is deprecated patchelf based hermes versioning
  - replace duplicated runReactNativeCodegenAndroidAsync with `Codegen.runReactNativeCodegenAsync`
  - update versioning script to support building in-place from react-native-lab
  - update for react-native 0.70
  - update versionCxx for expo-modules-core
  - support other new style vendoring modules
    - @react-native-community/slider
    - react-native-gesture-handler (with cxx files but they're only for new architecture)
    - react-native-screens (with cxx files but they're only for new architecture)
    - react-native-svg
    - react-native-reanimated (with cxx files)
  - remove old reanimated versioning scripts 

# Test Plan

```
$ et add-sdk -p android -s 47.0.0
$ cd android && ./gradlew :app:installVersionedDebug
# smoke test on sdk 47 NCL
```
  • Loading branch information
Kudo authored Oct 21, 2022
1 parent e03ccea commit 6239b2d
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 692 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions packages/expo-localization/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 🐛 Bug fixes

- Fixed build error for setting `compileSdkVersion` to 33. ([#19518](https://github.com/expo/expo/pull/19518) by [@kudo](https://github.com/kudo))

### ⚠️ Notices

- Deprecated existing constants API while keeping backwards compatibility. ([#19019](https://github.com/expo/expo/pull/19019) by [@aleqsio](https://github.com/aleqsio))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class LocalizationModule : Module() {
val locales = mutableListOf<Map<String, Any?>>()
val localeList: LocaleListCompat = LocaleListCompat.getDefault()
for (i in 0 until localeList.size()) {
val locale: Locale = localeList.get(i)
val locale: Locale = localeList.get(i) ?: continue
val decimalFormat = DecimalFormatSymbols.getInstance(locale)
locales.add(
mapOf(
Expand Down
13 changes: 10 additions & 3 deletions tools/src/Codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ReactNativeCodegenParameters {
name: string;

// library type
type: 'components' | 'modules';
type: 'components' | 'modules' | 'all';

// platform for generated code
platform: 'android' | 'ios';
Expand All @@ -26,6 +26,9 @@ export interface ReactNativeCodegenParameters {

// keep the intermediate schema.json (default is false)
keepIntermediateSchema?: boolean;

// java package name
javaPackageName?: string;
}

export async function runReactNativeCodegenAsync(params: ReactNativeCodegenParameters) {
Expand All @@ -45,7 +48,7 @@ export async function runReactNativeCodegenAsync(params: ReactNativeCodegenParam
await spawnAsync('node', [genSchemaScript, schemaOutputPath, params.jsSrcsDir]);

// generate code from schema.json
await spawnAsync('node', [
const genCodeArgs = [
genCodeScript,
'--platform',
params.platform,
Expand All @@ -57,7 +60,11 @@ export async function runReactNativeCodegenAsync(params: ReactNativeCodegenParam
params.name,
'--libraryType',
params.type,
]);
];
if (params.javaPackageName) {
genCodeArgs.push('--javaPackageName', params.javaPackageName);
}
await spawnAsync('node', genCodeArgs);

const keepIntermediateSchema = params.keepIntermediateSchema ?? false;
if (!keepIntermediateSchema) {
Expand Down
16 changes: 16 additions & 0 deletions tools/src/versioning/android/expoModulesTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ function expoModulesBaseTransforms(abiVersion: string): FileTransforms {
export function expoModulesTransforms(module: string, abiVersion: string): FileTransforms {
const base = expoModulesBaseTransforms(abiVersion);
const moduleTransforms: Record<string, FileTransforms> = {
'expo-modules-core': {
content: [
{
// We don't have dedicated gradle files for versioned expo-modules.
// For the BuildConfig, replace with unversioned expoview BuildConfig.
paths: './**/*.{java,kt}',
find: new RegExp(`\\bimport ${abiVersion}\\.expo\\.modules\\.BuildConfig`, 'g'),
replaceWith: 'import host.exp.expoview.BuildConfig',
},
],
},
'expo-updates': {
content: [
{
Expand All @@ -64,6 +75,11 @@ export function expoModulesTransforms(module: string, abiVersion: string): FileT
text
),
},
{
paths: './src/main/{java,kotlin}/expo/modules/updates/UpdatesPackage.kt',
find: 'BuildConfig.EX_UPDATES_NATIVE_DEBUG',
replaceWith: 'false',
},
],
},
};
Expand Down
93 changes: 24 additions & 69 deletions tools/src/versioning/android/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { searchFilesAsync } from '../../Utils';
import { copyExpoviewAsync } from './copyExpoview';
import { expoModulesTransforms } from './expoModulesTransforms';
import { packagesToKeep } from './packagesConfig';
import { deleteLinesBetweenTags } from './utils';
import { versionCxxExpoModulesAsync } from './versionCxx';
import { updateVersionedReactNativeAsync } from './versionReactNative';
import { removeVersionedVendoredModulesAsync } from './versionVendoredModules';
Expand Down Expand Up @@ -160,7 +159,10 @@ async function findAndPrintVersionReferencesInSourceFilesAsync(version: string):
);
let matchesCount = 0;

const files = await glob('**/{src/**/*.@(java|kt|xml),build.gradle}', { cwd: ANDROID_DIR });
const files = await glob('**/{src/**/*.@(java|kt|xml),build.gradle}', {
cwd: ANDROID_DIR,
ignore: 'vendored/**/*',
});

for (const file of files) {
const filePath = path.join(ANDROID_DIR, file);
Expand Down Expand Up @@ -221,7 +223,7 @@ export async function removeVersionAsync(version: string) {
await removeFromManifestAsync(sdkMajorVersion, templateManifestPath);

// Remove vendored modules
await removeVersionedVendoredModulesAsync(Number(version));
await removeVersionedVendoredModulesAsync(version);

// Remove SDK version from the list of supported SDKs
await removeFromSdkVersionsAsync(version, sdkVersionsPath);
Expand Down Expand Up @@ -415,45 +417,6 @@ async function cleanUpAsync(version: string) {
);
}

async function prepareReanimatedAsync(version: string): Promise<void> {
const abiVersion = version.replace(/\./g, '_');
const abiName = `abi${abiVersion}`;
const versionedExpoviewPath = versionedExpoviewAbiPath(abiName);
const buildGradlePath = path.join(versionedExpoviewPath, 'build.gradle');

const buildReanimatedSO = async () => {
await spawnAsync(`./gradlew :expoview-${abiName}:packageNdkLibs`, [], {
shell: true,
cwd: path.join(versionedExpoviewPath, '../../'),
stdio: 'inherit',
});
};

const removeLeftoverDirectories = async () => {
const mainPath = path.join(versionedExpoviewPath, 'src', 'main');
const toRemove = ['Common', 'JNI', 'cpp'];
for (const dir of toRemove) {
await fs.remove(path.join(mainPath, dir));
}
};

const removeLeftoversFromGradle = async () => {
const buildGradle = await fs.readFile(buildGradlePath, 'utf-8');
await fs.writeFile(
buildGradlePath,
deleteLinesBetweenTags(
/WHEN_PREPARING_REANIMATED_REMOVE_FROM_HERE/,
/WHEN_PREPARING_REANIMATED_REMOVE_TO_HERE/,
buildGradle
)
);
};

await buildReanimatedSO();
await removeLeftoverDirectories();
await removeLeftoversFromGradle();
}

async function exportReactNdks() {
const versionedRN = path.join(versionedReactAndroidPath, '..');
await spawnAsync(`./gradlew :ReactAndroid:packageReactNdkLibs`, [], {
Expand Down Expand Up @@ -482,51 +445,43 @@ async function exportReactNdksIfNeeded() {
}

export async function addVersionAsync(version: string) {
console.log(' 🛠 1/10: Updating android/versioned-react-native...');
await updateVersionedReactNativeAsync(
Directories.getReactNativeSubmoduleDir(),
ANDROID_DIR,
version
);
console.log(' ✅ 1/10: Finished\n\n');
console.log(' 🛠 1/9: Updating android/versioned-react-native...');
await updateVersionedReactNativeAsync(ANDROID_DIR, version);
console.log(' ✅ 1/9: Finished\n\n');

console.log(' 🛠 2/10: Building versioned ReactAndroid AAR...');
console.log(' 🛠 2/9: Building versioned ReactAndroid AAR...');
await spawnAsync('./android-build-aar.sh', [version], {
shell: true,
cwd: SCRIPT_DIR,
stdio: 'inherit',
});
console.log(' ✅ 2/10: Finished\n\n');
console.log(' ✅ 2/9: Finished\n\n');

console.log(' 🛠 3/10: Creating versioned expoview package...');
console.log(' 🛠 3/9: Creating versioned expoview package...');
await copyExpoviewAsync(version, ANDROID_DIR);
console.log(' ✅ 3/10: Finished\n\n');
console.log(' ✅ 3/9: Finished\n\n');

console.log(' 🛠 4/10: Exporting react ndks if needed...');
console.log(' 🛠 4/9: Exporting react ndks if needed...');
await exportReactNdksIfNeeded();
console.log(' ✅ 4/10: Finished\n\n');

console.log(' 🛠 5/10: prepare versioned Reanimated...');
await prepareReanimatedAsync(version);
console.log(' ✅ 5/10: Finished\n\n');
console.log(' ✅ 4/9: Finished\n\n');

console.log(' 🛠 6/10: Creating versioned expo-modules packages...');
console.log(' 🛠 5/9: Creating versioned expo-modules packages...');
await copyExpoModulesAsync(version);
console.log(' ✅ 6/10: Finished\n\n');
console.log(' ✅ 5/9: Finished\n\n');

console.log(' 🛠 7/10: Versoning c++ libraries for expo-modules...');
console.log(' 🛠 6/9: Versoning c++ libraries for expo-modules...');
await versionCxxExpoModulesAsync(version);
console.log(' ✅ 7/10: Finished\n\n');
console.log(' ✅ 6/9: Finished\n\n');

console.log(' 🛠 8/10: Adding extra versioned activites to AndroidManifest...');
console.log(' 🛠 7/9: Adding extra versioned activites to AndroidManifest...');
await addVersionedActivitesToManifests(version);
console.log(' ✅ 8/10: Finished\n\n');
console.log(' ✅ 7/9: Finished\n\n');

console.log(' 🛠 9/10: Registering new version under sdkVersions config...');
console.log(' 🛠 8/9: Registering new version under sdkVersions config...');
await registerNewVersionUnderSdkVersions(version);
console.log(' ✅ 9/10: Finished\n\n');
console.log(' ✅ 8/9: Finished\n\n');

console.log(' 🛠 10/10: Misc cleanup...');
console.log(' 🛠 9/9: Misc cleanup...');
await cleanUpAsync(version);
console.log(' ✅ 10/10: Finished');
console.log(' ✅ 9/9: Finished');
}
6 changes: 0 additions & 6 deletions tools/src/versioning/android/libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ export const JniLibNames = [
'rrc_unimplementedview',
'rrc_view',
'runtimeexecutor',

// TODO: considering versioning prebuilt fbjni by patchelf after RN 0.65 which has newer fbjni version.
// or simply upgrade old SDK to use latest fbjni.
//
// 'fbjni',
// 'libfbjni',
];

// this list is used in the shell scripts as well as directly by expotools
Expand Down
2 changes: 1 addition & 1 deletion tools/src/versioning/android/reactNativeTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function reactNativeCmakeTransforms(abiVersion: string): FileTransform[] {
})),
{
paths: 'CMakeLists.txt',
find: 'add_react_android_subdir(build/generated/source/codegen/jni)',
find: 'add_react_build_subdir(generated/source/codegen/jni)',
replaceWith: 'add_react_android_subdir(../codegen/jni)',
},
{
Expand Down
59 changes: 9 additions & 50 deletions tools/src/versioning/android/transforms/expoviewTransforms.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import escapeRegExp from 'lodash/escapeRegExp';

import { transformString } from '../../../Transforms';
import { FileTransform, FileTransforms, StringTransform } from '../../../Transforms.types';
import { baseCmakeTransforms } from '../cmakeTransforms';
import { JniLibNames } from '../libraries';
import { FileTransforms } from '../../../Transforms.types';
import { packagesToKeep, packagesToRename } from '../packagesConfig';
import { deleteLinesBetweenTags } from '../utils';

Expand Down Expand Up @@ -80,54 +77,16 @@ export function expoviewTransforms(abiVersion: string): FileTransforms {
find: /temporarydonotversion\./g,
replaceWith: '',
},
// currently it's matching only reanimated
...[...JniLibNames, 'fb', 'fbjni'].map((libName) => ({
paths: '*.java',
find: new RegExp(`(SoLoader|System).loadLibrary\\\("${escapeRegExp(libName)}"\\\)`),
replaceWith: `$1.loadLibrary("${libName}_${abiVersion}")`,
})),
{
paths: '*.{java,h,cpp}',
find: /versioned\/host\/exp\/exponent\/modules\/api\/reanimated/g,
replaceWith: `${abiVersion}/host/exp/exponent/modules/api/reanimated`,
paths: './**/reanimated/NativeProxy.java',
find: /\b(com\.swmansion\.)/g,
replaceWith: `${abiVersion}.$1`,
},
{
paths: './**/ExpoTurboPackage.kt',
find: /\bimport (com\.swmansion\.)/g,
replaceWith: `import ${abiVersion}.$1`,
},
...reanimatedCmakeTransforms(abiVersion),
],
};
}

function reanimatedCmakeTransforms(abiVersion: string): FileTransform[] {
const libNames = JniLibNames.map((lib: string): string =>
lib.startsWith('lib') ? lib.slice(3) : lib
).filter((lib: string) => !['fbjni'].includes(lib));
const renameSecondArg = (text: string) =>
transformString(
text,
libNames.map((lib) => ({
find: new RegExp(`^(\\\s*\\\S+\\\s+)${escapeRegExp(lib)}($|\\\s)`),
replaceWith: `$1${lib}_${abiVersion}$2`,
}))
);

return [
...baseCmakeTransforms(abiVersion, libNames).map((transform: StringTransform) => ({
paths: 'CMakeLists.txt',
...transform,
})),
{
paths: 'CMakeLists.txt',
find: /(find_library\()([\s\S]*?)(\))/g,
replaceWith: (_, p1, p2, p3) => [p1, renameSecondArg(p2), p3].join(''),
},
{
paths: 'CMakeLists.txt',
find: 'set (PACKAGE_NAME "reanimated")',
replaceWith: `set (PACKAGE_NAME "reanimated_${abiVersion}")`,
},
{
paths: 'CMakeLists.txt',
find: /\b(libhermes)\b/,
replaceWith: `$1_${abiVersion}`,
},
];
}
Loading

0 comments on commit 6239b2d

Please sign in to comment.