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

Android Failure: node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 213 #35887

Closed
suhaswagre opened this issue Jan 19, 2023 · 9 comments
Labels
Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged.

Comments

@suhaswagre
Copy link

suhaswagre commented Jan 19, 2023

Description

Hello everyone, I am trying to upgrade my React Native (RN) app from version 0.61.5 to 0.69.7 with the help of react native upgrade helper, I have made all the required changes on js side and native side of the code, but when I tried to clean/rebuild the Android project in the Android Studio after making all the mentioned changes I am facing an issue like below:
Screenshot 2023-01-19 at 1 31 39 PM

:ReactNative:Unexpected empty result of running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command.
:ReactNative:Running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command failed.

FAILURE: Build failed with an exception.

  • Where:
    Script '/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 213

  • What went wrong:
    A problem occurred evaluating script.

/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/metro/src/Server.js:390 processRequest = (req, res, next) => { ^SyntaxError: Unexpected token = at Module._compile (internal/modules/cjs/loader.js:721:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/metro/src/shared/output/bundle.js:14:16) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)

Version

0.69.7

Output of npx react-native info

System:
OS: macOS 11.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 143.81 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 19.4.0 - ~/.nvm/versions/node/v19.4.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v19.4.0/bin/yarn
npm: 9.2.0 - ~/.nvm/versions/node/v19.4.0/bin/npm
Watchman: 2022.12.12.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.17 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.7 => 0.69.7
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Make all the changes mentioned here on JS side and respective Android platform changes.
  2. Open Android Studio and try to clean/build the Android project.

Snack, code example, screenshot, or link to a repository

Here.

@cortinico
Copy link
Contributor

What happens if you run:

node -e "console.log(require('@react-native-community/cli').bin);"

in your console?

The output should be:

/<project_path>/node_modules/@react-native-community/cli/build/bin.js
``

If not, then you're either using a old version of the react-native CLI (perhaps globally installed) or your `node_modules` folder is missing files, so you should remove it and run `yarn` again.

@suhaswagre
Copy link
Author

node -e "console.log(require('@react-native-community/cli').bin);

Hi @cortinico, thanks for the reply, when I run this I get the expected result i.e /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/cli/build/bin.js

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 19, 2023
@cortinico
Copy link
Contributor

Then this looks like a local issue. I would suggest you:

  1. Try to build from the command line and open Android Studio only once you have a green build from the CLI
  2. Cleanup all the caches (delete node_modules).
  3. Remove the android/app/build and android/build folder

If still failing, please run react-native run-android in a terminal and copy here the whole build log.

@suhaswagre
Copy link
Author

suhaswagre commented Jan 19, 2023

Hi @cortinico please find the build log below:

> Task :app:compileMyAppDebugJavaWithJavac FAILED

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

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

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
675 actionable tasks: 669 executed, 6 up-to-date
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/appcenter-crashes/android/src/main/java/com/microsoft/appcenter/reactnative/crashes/AppCenterReactNativeCrashesListener.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/RNBranchModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/AgingHash.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/Utility.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-video/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@sentry/react-native/android/src/main/java/io/sentry/react/RNSentryModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: [1] Wrote GeneratedAppGlideModule with: [com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule]
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:23: error: package com.reactnativecommunity.cookies does not exist
import com.reactnativecommunity.cookies.CookieManagerPackage;
                                       ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:49: error: package me.aelesia does not exist
import me.aelesia.ActionSheetAndroidPackage;
                 ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:91: error: package com.wenkesj.voice does not exist
import com.wenkesj.voice.VoicePackage;
                        ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileMyAppDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for 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

BUILD FAILED in 52s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installMyAppDebug -PreactNativeDevServerPort=8081
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/appcenter-crashes/android/src/main/java/com/microsoft/appcenter/reactnative/crashes/AppCenterReactNativeCrashesListener.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/RNBranchModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/AgingHash.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/Utility.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/VirtualView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-video/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@sentry/react-native/android/src/main/java/io/sentry/react/RNSentryModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: [1] Wrote GeneratedAppGlideModule with: [com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule]
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:23: error: package com.reactnativecommunity.cookies does not exist
import com.reactnativecommunity.cookies.CookieManagerPackage;
                                       ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:49: error: package me.aelesia does not exist
import me.aelesia.ActionSheetAndroidPackage;
                 ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:91: error: package com.wenkesj.voice does not exist
import com.wenkesj.voice.VoicePackage;
                        ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileMyAppDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for 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

BUILD FAILED in 52s

    at makeError (/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/execa/index.js:174:9)
    at /Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/execa/index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@cortinico
Copy link
Contributor

So the error you were seing is resolved. Now your app is failing to build because it can't find the autolinked libraries;

/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:23: error: package com.reactnativecommunity.cookies does not exist
import com.reactnativecommunity.cookies.CookieManagerPackage;
                                       ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:49: error: package me.aelesia does not exist
import me.aelesia.ActionSheetAndroidPackage;
                 ^
/Users/suhas.wagre/Projects/React Native/11_Jan_2020/blc_upgrade/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:91: error: package com.wenkesj.voice does not exist
import com.wenkesj.voice.VoicePackage;

Can you copy-paste your build.gradle files (both of them) and the settings.gradle file?

@cortinico cortinico added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Jan 19, 2023
@suhaswagre
Copy link
Author

suhaswagre commented Jan 20, 2023

Hi @cortinico Please find the requested files below:

android/app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
//apply plugin: 'io.fabric'

import com.android.build.OutputFile
import java.util.regex.Matcher
import java.util.regex.Pattern

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.13.4'
    }
}

def sdkVersion = "9.8.02"

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: '../../node_modules/react-native/react.gradle'` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: 'index.android.bundle',
 *
 *   // the entry file for bundle generation
 *   entryFile: 'index.android.js',
 *
 *   // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
 *   bundleCommand: 'ram-bundle',
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where 'package.json' lives
 *   root: '../../',
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: '$buildDir/intermediates/assets/debug',
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: '$buildDir/intermediates/assets/release',
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: '$buildDir/intermediates/res/merged/debug',
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: '$buildDir/intermediates/res/merged/release',
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ['android/**', 'ios/**'],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ['node'],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
        entryFile   : 'index.js',
        enableHermes: false,  // clean and rebuild if changing
]


project.ext.envConfigFiles = [
        myapp1    : 'config/.env.myapp1',
        myapp2 : 'config/.env.myapp2',
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: '../../node_modules/react-native-code-push/android/codepush.gradle'

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc-intl:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get('enableHermes', false);

def getCurrentFlavour() {
    Gradle gradle = getGradle()
    String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
    print(tskReqStr.toString())

    Pattern pattern
    if (tskReqStr.contains("assemble"))
        pattern = Pattern.compile("assemble(\\w+)(release|releasestaging|debug)")
    else
        pattern = Pattern.compile("generate(\\w+)(release|releasestaging|debug)")
    Matcher matcher = pattern.matcher(tskReqStr)
    if (matcher.find()) {
        def value = matcher.group(1).toLowerCase()
        return value
    } else {
        return ""
    }
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    ndkVersion = rootProject.ext.ndkVersion
    flavorDimensions 'default'
    kotlinOptions {
        jvmTarget = '11'
    }

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode project.inCode
        versionName project.inVersion
        resValue 'string', 'build_config_package', 'com.myapp'
        multiDexEnabled true
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
        if (isNewArchitectureEnabled()) {
            // We configure the NDK build only if you decide to opt-in for the New Architecture.
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_PLATFORM=android-21",
                            "APP_STL=c++_shared",
                            "NDK_TOOLCHAIN_VERSION=clang",
                            "GENERATED_SRC_DIR=$buildDir/generated/source",
                            "PROJECT_BUILD_DIR=$buildDir",
                            "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
                            "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
                            "NODE_MODULES_DIR=$rootDir/../node_modules"
                    cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
                    cppFlags "-std=c++17"
                    // Make sure this target name is the same you specify inside the
                    // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
                    targets "landmarkgroupreactapps_appmodules"
                }
            }
            if (!enableSeparateBuildPerCPUArchitecture) {
                ndk {
                    abiFilters (*reactNativeArchitectures())
                }
            }
        }
    }

    if (isNewArchitectureEnabled()) {
        // We configure the NDK build only if you decide to opt-in for the New Architecture.
        externalNativeBuild {
            ndkBuild {
                path "$projectDir/src/main/jni/Android.mk"
            }
        }
        def reactAndroidProjectDir = project(':ReactAndroid').projectDir
        def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
            dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
            from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
            into("$buildDir/react-ndk/exported")
        }
        def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
            dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
            from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
            into("$buildDir/react-ndk/exported")
        }
        afterEvaluate {
            // If you wish to add a custom TurboModule or component locally,
            // you should uncomment this line.
            // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
            preDebugBuild.dependsOn(packageReactNdkDebugLibs)
            preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
            // Due to a bug inside AGP, we have to explicitly set a dependency
            // between configureNdkBuild* tasks and the preBuild tasks.
            // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
            configureNdkBuildRelease.dependsOn(preReleaseBuild)
            configureNdkBuildDebug.dependsOn(preDebugBuild)
            reactNativeArchitectures().each { architecture ->
                tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
                    dependsOn("preDebugBuild")
                }
                tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
                    dependsOn("preReleaseBuild")
                }
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86_64'
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'storePassword'
            keyAlias 'key'
            keyPassword 'password'
        }
        release {
            storeFile file('release.keystore')
            storePassword 'storePassword'
            keyAlias 'alias key'
            keyPassword 'password1'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            applicationIdSuffix ".debug"
            manifestPlaceholders = [branch_test_mode: "true"]
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            manifestPlaceholders = [branch_test_mode: "false"]
        }
        releasestaging {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            initWith release
            matchingFallbacks = ['release']
        }
        releaseproductionstaging {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            initWith release
            matchingFallbacks = ['release']
        }
    }

    productFlavors {
        myapp1 {
            applicationId 'com.hit.myapp1'
            resValue 'string', 'flavored_app_name', 'MyApp1'
        }
        myapp2 {
            applicationId 'com.hit.myapp2'
            resValue 'string', 'flavored_app_name', 'MyApp2'
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ['armeabi-v7a': 1, 'x86': 2, 'arm64-v8a': 3, 'x86_64': 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libjsc.so'
        pickFirst 'lib/arm64-v8a/libjsc.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    }
    buildToolsVersion = buildToolsVersion
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
    implementation project(':react-native-config')
    implementation 'com.facebook.android:facebook-android-sdk:15.1.0'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    // Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics:21.2.0'
    //GIF
    implementation 'com.facebook.fresco:fresco:2.6.0'
    implementation 'com.facebook.fresco:animated-gif:2.0.0'
    //For WebP support, including animated WebP
    implementation 'com.facebook.fresco:animated-webp:1.10.0'
    implementation 'com.facebook.fresco:webpsupport:1.10.0'

    //MOE Integration Start
    implementation "com.moengage:moe-android-sdk:11.6.02"
    implementation "com.moengage:addon-inbox:6.0.2"
    implementation("com.moengage:rich-notification:2.2.01")

    implementation("androidx.core:core:1.9.0")
    implementation("androidx.appcompat:appcompat:1.5.1")
    implementation("androidx.lifecycle:lifecycle-process:2.5.1")
    implementation 'com.google.firebase:firebase-messaging:23.1.1'
    //MOE Integration End

    //TAG MANAGER
    //implementation 'com.google.android.gms:play-services-tagmanager:17.0.0'
    //implementation 'com.google.android.gms:play-services-analytics:17.0.0'

    //Onesignal
    implementation 'com.onesignal:OneSignal:3.15.6'
    //GA integration
    implementation 'com.google.android.gms:play-services-tagmanager:18.0.2'
    implementation 'com.google.android.gms:play-services-analytics:18.0.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'com.google.firebase:firebase-appindexing:20.0.0' // App indexing
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'

    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

    //Glide library for image loading
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    // Glide v4 uses this new annotation processor -- see https://bumptech.github.io/glide/doc/generatedapi.html
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    //LiveChat SDK
    implementation 'com.github.livechat:chat-window-android:v2.0.3'

    //NativeApiClient
    implementation(platform("com.squareup.okhttp3:okhttp-bom:4.4.1"))
    implementation("com.squareup.okhttp3:okhttp")              // No version!
    implementation("com.squareup.okhttp3:okhttp-urlconnection") // No version!
    implementation("com.squareup.okhttp3:logging-interceptor")

    // debug dependencies
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = '../../node_modules/hermesvm/android/';
        debugImplementation files(hermesPath + 'hermes-debug.aar')
        releaseImplementation files(hermesPath + 'hermes-release.aar')
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.implementation
    into 'libs'
}
apply from: file('../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle'); applyNativeModulesAppBuildGradle(project)
// Google services
apply plugin: 'com.google.gms.google-services'

def isNewArchitectureEnabled() {
    // To opt-in for the New Architecture, you can either:
    // - Set `newArchEnabled` to true inside the `gradle.properties` file
    // - Invoke gradle with `-newArchEnabled=true`
    // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
    return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.apache.tools.ant.taskdefs.condition.Os
buildscript {
    ext {
        kotlin_version = '1.7.0'
        //compose_version = '1.1.0-beta01'
        buildToolsVersion = "31.0.0"
        minSdkVersion = 16
        compileSdkVersion = 31
        targetSdkVersion = 31
        supportLibVersion = "28.0.0"
        playServicesVersion = "15.0.1"
        androidMapsUtilsVersion = "0.5+"
        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
          url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:7.1.1')
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        // Google services
        classpath 'com.google.gms:google-services:4.3.5'

        // Fabric tools
        // classpath 'io.fabric.tools:gradle:1.28.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version";

        // Add the AppGallery Connect plugin configuration.
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        //classpath 'com.huawei.agconnect:agcp:1.6.0.300'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
        mavenCentral()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.google.com' }
    }
}

project.ext {
    targetSdkVersion = 33
    compileSdkVersion = 33
    minSdkVersion = 21
    buildToolsVersion = '30.0.2'
    supportLibVersion = '28.0.0'
    playservices = '15.0.1'
    ndkVersion = '21.4.7075529'

    Code = 500
    Version = '8.4'
    navigationVersion = "1.0.0"
    excludeAppGlideModule = true
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

settings.gradle

rootProject.name = 'MyApp'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app', ':react-native-code-push', ':react-native-gesture-handler', ':react-native-moengage', ':react-native-config'
project(':react-native-moengage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-moengage/android')
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
includeBuild('../node_modules/react-native-gradle-plugin')
if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
    include(":ReactAndroid")
    project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
    include(":ReactAndroid:hermes-engine")
    project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine')
}

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 20, 2023
@cortinico cortinico added Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Attention Issues where the author has responded to feedback. labels Jan 20, 2023
@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ It looks like your issue is missing a reproducible example. Please provide a Snack or a repository that demonstrates the issue you are reporting in a minimal, complete, and reproducible manner.

@cortinico
Copy link
Contributor

Thanks for sharing them. Your setup looks correct, but you have a lot of custom logic inside your app/build.gradle which might cause this issue.

I would need a repro to look further into this

@suhaswagre
Copy link
Author

Hi @cortinico, thanks for the help I was able to resolve the issue by simply removing the dependencies whose imports were unrecognisable and I was able to compile and install the Android app.
Thank you once again!

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 24, 2023
@cortinico cortinico added Resolution: Fixed A PR that fixes this issue has been merged. and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Android applications. Resolution: Fixed A PR that fixes this issue has been merged.
Projects
None yet
Development

No branches or pull requests

3 participants