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

feat(Android:Settings.gradle): Add ability to inject code on plugin level #1563

Merged
merged 5 commits into from
May 28, 2024

Conversation

RicardasN
Copy link
Collaborator

@RicardasN RicardasN commented May 21, 2024

Description

  • Adds the ability to inject extra bit of code into settings.gradle for when you need to do that configuring a plugin

Related issues

Notes for QA

To test, you should try the module user in question was having trouble configuring, code should look like this:

 "react-native-code-push": {
            "android": {
                "templateAndroid": {
                    "app_build_gradle": {
                        "apply": ["from: \"{{PLUGIN_ROOT}}/codepush.gradle\""]
                    },
                    "settings_gradle": {
                        "project": ["project(':react-native-code-push').projectDir = new File(\"{{PLUGIN_ROOT}}/android/app\")"],
                        "include": ["':react-native-code-push'"]
                    }
                },
                "package": "com.microsoft.codepush.react.CodePush",
                "path": "{{PLUGIN_ROOT}}/android",
                "projectName": "react-native-code-push"
            },
            "version": "^8.1.0"
        }

And as a result of the test, settings.gradle should have the necessary things added to it as per description of the plugin here

@RicardasN RicardasN marked this pull request as ready for review May 23, 2024 07:38
@pauliusguzas
Copy link
Collaborator

> Task :app:compileDebugKotlin FAILED
e: file:///Users/pauliusguzas/Desktop/renative/renative/packages/template-starter/platformBuilds/template_android/app/src/main/java/rnv_template/MainApplication.kt:15:12 Unresolved reference: microsoft

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 13s
53 actionable tasks: 48 executed, 5 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor

error Failed to build the app.
Error: Command failed with exit code 1: ./gradlew app:installDebug -x lint -PreactNativeDevServerPort=8083
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at Function.module.exports.sync (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:194:17)
    at build (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/buildAndroid/index.js:68:22)
    at runOnSpecificDevice (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:221:33)
    at buildAndRun (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:183:12)
    at Object.runAndroid [as func] (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:116:10)
    at Command.handleAction (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:118:23)
    at Command.listener [as _actionHandler] (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:482:17)
    at /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1283:27)
    at /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1081:27
    at Command._chainOrCall (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1177:12)
    at Command._dispatchSubcommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1077:23)
    at Command._parseCommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1248:19)
    at Command.parse (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:909:10)
info Run CLI with --verbose flag for more details.
error: ⨯ ○ run: COMMAND:

node  /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554

FAILED with ERROR:

Error: Command failed with exit code 1: node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


┌─────────────────────────────────────────────────────────────────┐
│ ⨯ SUMMARY | 5/23/2024, 11:14:24 AM | rnv@1.0.0-rc.19            │
│ $ rnv run -p android -r                                         │
├─────────────────────────────────────────────────────────────────┤
│ Project: @rnv/template-starter@1.0.0-rc.19                      │
│ Workspace: rnv                                                  │
│ Platform (-p): android                                          │
│ Engine: @rnv/engine-rn                                          │
│ App Config (-c): template                                       │
│ Build Scheme (-s): debug                                        │
│ Target (-t): Pixel_4_API_29                                     │
│ Reset Project (-r): true                                        │
│ Supported Platforms: ios, android, androidtv, firetv, androidwear, web, tizen, tvos, webos, macos, windows, tizenwatch, kaios, chromecast, linux, windows
│ Env Info: darwin | x64 | node v18.17.0                          │
│ Executed Time: 0h:0m:22s:315ms                                  │
│ warn: ○ platform configure: Updates to package.json are required: (only info. skipping due to template mode)
│ warn: ○ configureSoft: Updates to package.json are required: (only info. skipping due to template mode)
│ error: ⨯ ○ run: COMMAND:

node  /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554

FAILED with ERROR:

Error: Command failed with exit code 1: node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


│ Project location: ./platformBuilds/template_android             │
└─────────────────────────────────────────────────────────────────┘
error: ⨯ ○ run: COMMAND:

node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/local-cli/cli.js start --port 8083 --no-interactive --config=metro.config.js --reset-cache

FAILED with ERROR:

Error: Command was killed with SIGTERM (Termination): node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/local-cli/cli.js start --port 8083 --no-interactive --config=metro.config.js --reset-cache
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


pauliusguzas@MBP-de-Flexn template-starter %

Getting this after adding said snippet to renative.json plugins

@RicardasN
Copy link
Collaborator Author

> Task :app:compileDebugKotlin FAILED
e: file:///Users/pauliusguzas/Desktop/renative/renative/packages/template-starter/platformBuilds/template_android/app/src/main/java/rnv_template/MainApplication.kt:15:12 Unresolved reference: microsoft

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 13s
53 actionable tasks: 48 executed, 5 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor

error Failed to build the app.
Error: Command failed with exit code 1: ./gradlew app:installDebug -x lint -PreactNativeDevServerPort=8083
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at Function.module.exports.sync (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:194:17)
    at build (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/buildAndroid/index.js:68:22)
    at runOnSpecificDevice (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:221:33)
    at buildAndRun (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:183:12)
    at Object.runAndroid [as func] (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:116:10)
    at Command.handleAction (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:118:23)
    at Command.listener [as _actionHandler] (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:482:17)
    at /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1283:27)
    at /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1081:27
    at Command._chainOrCall (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1177:12)
    at Command._dispatchSubcommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1077:23)
    at Command._parseCommand (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:1248:19)
    at Command.parse (/Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/node_modules/commander/lib/command.js:909:10)
info Run CLI with --verbose flag for more details.
error: ⨯ ○ run: COMMAND:

node  /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554

FAILED with ERROR:

Error: Command failed with exit code 1: node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


┌─────────────────────────────────────────────────────────────────┐
│ ⨯ SUMMARY | 5/23/2024, 11:14:24 AM | rnv@1.0.0-rc.19            │
│ $ rnv run -p android -r                                         │
├─────────────────────────────────────────────────────────────────┤
│ Project: @rnv/template-starter@1.0.0-rc.19                      │
│ Workspace: rnv                                                  │
│ Platform (-p): android                                          │
│ Engine: @rnv/engine-rn                                          │
│ App Config (-c): template                                       │
│ Build Scheme (-s): debug                                        │
│ Target (-t): Pixel_4_API_29                                     │
│ Reset Project (-r): true                                        │
│ Supported Platforms: ios, android, androidtv, firetv, androidwear, web, tizen, tvos, webos, macos, windows, tizenwatch, kaios, chromecast, linux, windows
│ Env Info: darwin | x64 | node v18.17.0                          │
│ Executed Time: 0h:0m:22s:315ms                                  │
│ warn: ○ platform configure: Updates to package.json are required: (only info. skipping due to template mode)
│ warn: ○ configureSoft: Updates to package.json are required: (only info. skipping due to template mode)
│ error: ⨯ ○ run: COMMAND:

node  /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554

FAILED with ERROR:

Error: Command failed with exit code 1: node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/cli.js run-android --mode=Debug --no-packager --main-activity=SplashActivity --deviceId=emulator-5554
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


│ Project location: ./platformBuilds/template_android             │
└─────────────────────────────────────────────────────────────────┘
error: ⨯ ○ run: COMMAND:

node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/local-cli/cli.js start --port 8083 --no-interactive --config=metro.config.js --reset-cache

FAILED with ERROR:

Error: Command was killed with SIGTERM (Termination): node /Users/pauliusguzas/Desktop/renative/renative/node_modules/react-native/local-cli/cli.js start --port 8083 --no-interactive --config=metro.config.js --reset-cache
    at makeError (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/Users/pauliusguzas/Desktop/renative/renative/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)


pauliusguzas@MBP-de-Flexn template-starter %

Getting this after adding said snippet to renative.json plugins

The important part is the settings.gradle modified correctly? As I did not add support for the plugin for this exact reason, it requires more things, but there was no way before to modify settings.gradle as per ticket, so this PR aims to fix exactly that.

@pauliusguzas pauliusguzas self-requested a review May 23, 2024 08:46
@pavjacko pavjacko merged commit 278302c into release/1.0 May 28, 2024
11 checks passed
@pavjacko pavjacko deleted the fix/settings-gradle branch May 28, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants