diff --git a/README.md b/README.md index 6b9f99a9c..36bcecbf8 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,6 @@ This will ask you few questions about your project and generate a new project in - ES modules build for bundlers such as webpack - Flow definitions (copies .js files to .flow files) - TypeScript definitions (uses `tsc` to generate declaration files) -- Android AAR files If you created a project with `create-react-native-library`, `react-native-builder-bob` is **already pre-configured to build your project**. You don't need to configure it again. @@ -195,24 +194,6 @@ Example: ["typescript", { "project": "tsconfig.build.json" }] ``` -##### `aar` - -Enable assembling Android AAR files for a library for React Native modules including native code. - -The following options are supported: - -- `reverseJetify` (`boolean`): If your package is using [AndroidX](https://developer.android.com/jetpack/androidx), it's possible to convert the AAR with the `reverseJetify` option to use the [Android support Library](https://developer.android.com/topic/libraries/support-library) using the [`jetifier`](https://www.npmjs.com/package/jetifier) package. This is useful to publish packages for older projects which haven't migrated to AndroidX. - -- `androidPath` (`string`): You can specify a custom path to the `android` directory if it's not in the default location (`android` in the root of your project). - -- `androidBundleName`: By default, the generated `aar` file is named as `android.aar`. You can specify a custom name using this option. - -Example: - -```json -["aar", { "reverseJetify": true }] -``` - ### Commands The `bob` CLI exposes the following commands: diff --git a/packages/create-react-native-library/package.json b/packages/create-react-native-library/package.json index b8fe04889..1bc29c785 100644 --- a/packages/create-react-native-library/package.json +++ b/packages/create-react-native-library/package.json @@ -53,9 +53,6 @@ "validate-npm-package-name": "^4.0.0", "yargs": "^17.5.1" }, - "optionalDependencies": { - "jetifier": "^2.0.0" - }, "devDependencies": { "@babel/cli": "^7.17.10", "@babel/core": "^7.18.5", diff --git a/packages/react-native-builder-bob/package.json b/packages/react-native-builder-bob/package.json index 0f28c5f30..f8bb8610d 100644 --- a/packages/react-native-builder-bob/package.json +++ b/packages/react-native-builder-bob/package.json @@ -56,9 +56,6 @@ "which": "^2.0.2", "yargs": "^17.5.1" }, - "optionalDependencies": { - "jetifier": "^2.0.0" - }, "devDependencies": { "@babel/cli": "^7.17.10", "@types/babel__core": "^7.1.19", diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index df2be360e..b8c203c60 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -7,7 +7,6 @@ import { cosmiconfigSync } from 'cosmiconfig'; import isGitDirty from 'is-git-dirty'; import prompts, { type PromptObject } from './utils/prompts'; import * as logger from './utils/logger'; -import buildAAR from './targets/aar'; import buildCommonJS from './targets/commonjs'; import buildModule from './targets/module'; import buildTypescript from './targets/typescript'; @@ -123,11 +122,6 @@ yargs value: 'typescript', selected: /\.tsx?$/.test(entryFile), }, - { - title: 'aar - bundle android code to a binary', - value: 'aar', - selected: false, - }, ], validate: (input: string) => Boolean(input.length), }, @@ -404,15 +398,6 @@ yargs report.info(`Building target ${kleur.blue(targetName)}`); switch (targetName) { - case 'aar': - await buildAAR({ - root, - source: path.resolve(root, source as string), - output: path.resolve(root, output as string, 'aar'), - options: targetOptions, - report, - }); - break; case 'commonjs': await buildCommonJS({ root, diff --git a/packages/react-native-builder-bob/src/targets/aar.ts b/packages/react-native-builder-bob/src/targets/aar.ts deleted file mode 100644 index 2245d243c..000000000 --- a/packages/react-native-builder-bob/src/targets/aar.ts +++ /dev/null @@ -1,122 +0,0 @@ -import path from 'path'; -import kleur from 'kleur'; -import fs from 'fs-extra'; -import del from 'del'; -import androidAssemble from '../utils/androidAssemble'; -import jetifier from '../utils/jetifier'; -import type { Input } from '../types'; - -type TargetOptions = { - androidPath: string; - androidBundleName: string; - reverseJetify: boolean; -}; - -const defaultOptions: TargetOptions = { - androidPath: 'android', - androidBundleName: 'android.aar', - reverseJetify: false, -}; - -type Options = Input & { - options?: Partial; -}; - -async function createGradleFile(file: string) { - await fs.createFile(file); - await fs.writeFile( - file, - 'configurations.maybeCreate("default")\nartifacts.add("default", file(\'android.aar\'))' - ); -} - -export default async function build({ - root, - output, - options, - report, -}: Options) { - const targetOptions = { - ...defaultOptions, - ...options, - }; - - report.info( - `Cleaning up previous build at ${kleur.blue(path.relative(root, output))}` - ); - - await del([output]); - - await androidAssemble({ - root, - androidPath: targetOptions.androidPath, - report, - }); - - report.info( - `Creating new output directory at ${kleur.blue( - path.relative(root, output) - )}` - ); - await fs.mkdir(output); - - const sourceAar = path.join( - targetOptions.androidPath, - 'build', - 'outputs', - 'aar', - targetOptions.androidBundleName - ); - const targetAar = path.join(output, targetOptions.androidBundleName); - - report.info( - `Copying AAR from ${kleur.blue( - path.relative(root, sourceAar) - )} to ${kleur.blue(path.relative(root, targetAar))}` - ); - await fs.copyFile(sourceAar, targetAar); - - const gradleFile = path.join(output, 'build.gradle'); - report.info( - `Creating AAR Gradle file at ${kleur.blue(path.relative(root, gradleFile))}` - ); - await createGradleFile(gradleFile); - - if (targetOptions.reverseJetify) { - const supportOutputPath = path.join(output, 'support'); - report.info( - `Creating new support output directory at ${kleur.blue( - path.relative(root, supportOutputPath) - )}` - ); - await fs.mkdir(supportOutputPath); - - const supportAar = path.join( - supportOutputPath, - targetOptions.androidBundleName - ); - report.info( - `Using Jetifier to convert AAR from AndroidX to Support AAR at ${kleur.blue( - path.relative(root, supportAar) - )}` - ); - - await jetifier({ - root, - report, - input: targetAar, - output: supportAar, - reverse: true, - }); - - const supportGradleFile = path.join(supportOutputPath, 'build.gradle'); - report.info( - `Creating Support AAR Gradle file at ${kleur.blue( - path.relative(root, supportGradleFile) - )}` - ); - await createGradleFile(supportGradleFile); - } - - report.success(`Wrote files to ${kleur.blue(path.relative(root, output))}`); -} diff --git a/packages/react-native-builder-bob/src/types.ts b/packages/react-native-builder-bob/src/types.ts index 4d71052ef..16a9194cf 100644 --- a/packages/react-native-builder-bob/src/types.ts +++ b/packages/react-native-builder-bob/src/types.ts @@ -13,7 +13,7 @@ export type Input = { report: Report; }; -export type Target = 'aar' | 'commonjs' | 'module' | 'typescript'; +export type Target = 'commonjs' | 'module' | 'typescript'; export type Options = { source?: string; diff --git a/packages/react-native-builder-bob/src/utils/jetifier.ts b/packages/react-native-builder-bob/src/utils/jetifier.ts deleted file mode 100644 index c26ee0299..000000000 --- a/packages/react-native-builder-bob/src/utils/jetifier.ts +++ /dev/null @@ -1,46 +0,0 @@ -import path from 'path'; -import kleur from 'kleur'; -import { execFileSync } from 'child_process'; -import fs from 'fs-extra'; -import type { Report } from '../types'; - -type Options = { - root: string; - input: string; - output: string; - reverse: boolean; - report: Report; -}; - -export default async function jetifier({ - root, - input, - output, - reverse, -}: Options) { - const jetifierStandalone = path.join( - root, - 'node_modules', - '.bin', - 'jetifier-standalone' - ); - - if (await fs.pathExists(jetifierStandalone)) { - const args = ['-i', input, '-o', output]; - if (reverse) { - args.push('-r'); - } - - execFileSync(jetifierStandalone, args); - } else { - throw new Error( - `The ${kleur.blue( - 'jetifier' - )} binary doesn't seem to be installed under ${kleur.blue( - 'node_modules' - )}. Make sure you have added ${kleur.blue( - 'jetifier' - )} to your ${kleur.blue('devDependencies')}.` - ); - } -} diff --git a/yarn.lock b/yarn.lock index c9eeb1672..99baf3ed1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4381,11 +4381,6 @@ jake@^10.8.5: filelist "^1.0.1" minimatch "^3.0.4" -jetifier@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/jetifier/-/jetifier-2.0.0.tgz#699391367ca1fe7bc4da5f8bf691eb117758e4cb" - integrity sha512-J4Au9KuT74te+PCCCHKgAjyLlEa+2VyIAEPNCdE5aNkAJ6FAJcAqcdzEkSnzNksIa9NkGmC4tPiClk2e7tCJuQ== - "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"