facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.22k stars 626 forks source link

ReactNative build failed issuse at MainActivity.java #1088

Open Gnanesh009 opened 1 year ago

Gnanesh009 commented 1 year ago

MainActivity.java:26: error: constructor DefaultReactActivityDelegate in class DefaultReactActivityDelegate cannot be applied to given types;
return new DefaultReactActivityDelegate( ^ required: ReactActivity,String,boolean,boolean found: MainActivity,String,boolean reason: actual and formal argument lists differ in length 1 error

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

2: Task failed with an exception.

BUILD FAILED in 11s

at makeError (D:\GCRS\MItra\mitra\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)
at D:\GCRS\MItra\mitra\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runOnAllDevices (D:\GCRS\MItra\mitra\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:82:7)
at async Command.handleAction (D:\GCRS\MItra\mitra\node_modules\@react-native-community\cli\build\index.js:108:9)

info Fetching system and libraries information... System: OS: Windows 10 10.0.22621 CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz Memory: 2.61 GB / 15.71 GB Binaries: Node: 18.16.1 - C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 9.7.2 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Android NDK: 22.1.7171670 Windows SDK: AllowDevelopmentWithoutDevLicense: Enabled IDEs: Android Studio: AI-222.4459.24.2221.10121639 Visual Studio: Not Found Languages: Java: 11.0.19 npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: ^0.71.1 => 0.71.1 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

my android/build.gradle // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 kotlinVersion = "1.5.31" // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") } }

my android/app/buil.gradle

apply plugin: "com.android.application" apply plugin: "com.facebook.react"

/**

/**

/**

android { ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion

namespace "com.mitraapp"
defaultConfig {
    applicationId "com.mitraapp"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        // Caution! In production, you need to generate your own keystore file.
        // see https://reactnative.dev/docs/signed-apk-android.

        signingConfig signingConfigs.debug
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

}

dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android")

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

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
    implementation("com.facebook.react:hermes-android")
} else {
    implementation jscFlavor
}

}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

my gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists

packages.json

"dependencies": { "@react-native-async-storage/async-storage": "^1.19.3", "@react-native-camera-roll/camera-roll": "^5.7.2", "@react-native-community/geolocation": "^3.1.0", "@react-native-community/netinfo": "^9.4.1", "@react-navigation/native": "^6.1.7", "@react-navigation/native-stack": "^6.9.13", "i18next": "^23.5.1", "react": "18.2.0", "react-i18next": "^13.2.2", "react-native": "^0.71.1", "react-native-base64": "^0.2.1", "react-native-chart-kit": "^6.12.0", "react-native-elements": "^3.4.3", "react-native-image-crop-picker": "^0.40.0", "react-native-reanimated": "^2.14.4", "react-native-responsive-screen": "^1.4.2", "react-native-safe-area-context": "^4.6.3", "react-native-screens": "^3.20.0", "react-native-select-dropdown": "^3.4.0", "react-native-share": "^9.4.1", "react-native-svg": "^13.13.0", "react-native-svg-transformer": "^1.1.0", "react-native-vector-icons": "^10.0.0", "react-native-view-shot": "^3.0.2", "react-redux": "^8.1.2", "redux-thunk": "^2.4.2" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/eslint-config": "^0.72.2", "@react-native/metro-config": "^0.72.11", "@tsconfig/react-native": "^3.0.0", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1", "eslint": "^8.19.0", "jest": "^29.2.1", "metro-react-native-babel-preset": "0.76.8", "prettier": "^2.4.1", "react-test-renderer": "18.2.0", "typescript": "4.8.4" },

jdk version is 11

larinnim commented 1 year ago

Got the same error

shadow-shaman0209 commented 1 year ago

Me too. :(

ToshKoevoets commented 11 months ago

Not sure why this happened; but now the Java function seems to want a boolean for the last parameter to indicate getConcurrentReactEnabled, in the MainActivity.java.

The comment before already suggested that was needed, anyway, this is how to change it:

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
        this,
        getMainComponentName()
        // If you opted-in for the New Architecture, we enable the Fabric Renderer.
        DefaultNewArchitectureEntryPoint.getFabricEnabled(),
      );
  }

To this:

   /**
   * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
   * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
   * (aka React 18) with two boolean flags.
   */
  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
        this,
        getMainComponentName(),
        // If you opted-in for the New Architecture, we enable the Fabric Renderer.
        DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled
        // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
        DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled
        );
  }
cowboy-bebug commented 11 months ago

Yeah it should conform to the class defined here: https://github.com/facebook/react-native/blob/v0.71.14/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactActivityDelegate.kt#L25-L30

^ Insert the appropriate RN version number for your project