i was getting this error during build time of android after two weeks of install stripe sdk, it was running perfectly before. it also running and building perfectly in IOS devices.
enter image description here
enter image description here
To Reproduce
Install using this code
Run ```yarn android
Terminal get error at 76% , appear this error : Unchecked cast : >Task: app:checkDebugDuplicateClasses Failed ( picture below)
Versions::
React versio": "17.0.2",
React native version: "0.68.2",
Stripe version: 0.19.0
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 31
The error message says that there are duplicate bouncycastle modules in your Android project, and you should exclude one of them.
Go to /android folder and run ./gradlew app:dependencies to view the gradle dependency tree. Search org.bouncycastle and you should find two matches (e.g., one under com.stripe:stripe-3ds2-android and the other one under your other dependency)
Open the build.gradle file in /android/app folder and add the gradle configuration if you wish you exclude the bouncycastle required by Stripe.
implementation ('com.stripe:stripe-android:20.14.0') {
exclude group: "org.bouncycastle", module: "bcprov-jdk15to18"
}
I have fixed the issue by adding the following lines in app/build.gradle dependencies:
implementation (project(':stripe_stripe-react-native')) {
exclude group: "org.bouncycastle", module: "bcprov-jdk15to18"
}
Related
I have a live react native app, which was working fine. But now I need to made some changes to it but I am unable to do so after new updates and new gradle version. I have tried on multiple PCs and workspaces but all are of no use same error on every system pops up. giving some errors which are as under and attached screenshot.
FAILURE: Build failed with an exception.
The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':react-native-alarm-clock', ':react-native-webview'
What went wrong:
Execution failed for task ':invertase_react-native-apple-authentication:compileDebugKotlin'.
Screenshot of the error
another Screenshot of the error
I have a live react native app, which was working fine. But now I need to made some changes to it but I am unable to do so. I have tried on multiple PCs and workspaces but all are of no use same error on every system pops up.
add kotlin version in you android/build.gradle
buildscript {
ext {
...
kotlin_version='1.6.0' //add This change version with your installed kotlin version
...
}
repositories {
google()
mavenCentral()
}
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" //add This
...
}
}
Just go to build.gradle(Project:yourProjectName)
change
Plugin {
...
id 'org.jetbrains.kotlin.android' version '1.4.x' apply false
...
}
To
Plugin {
...
id 'org.jetbrains.kotlin.android' version '1.6.0' apply false
...
}
I am having problems running my React Native application that was running fine just yesterday. Therefore I ran the command:
npx react-native run-android -- --warning-mode=all
Which gives information starting with:
> Task :react-native-async-storage_async-storage:generateDebugRFile FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
FAILURE: Build failed with an exception.
...
* What went wrong:
Execution failed for task ':react-native-async-storage_async-storage:generateDebugRFile'.
> Could not resolve all files for configuration ':react-native-async-storage_async-storage:debugCompileClasspath'.
> Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-symbol-with-package-name, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-api}.
> Execution failed for JetifyTransform: C:\Users\pangi\.gradle\caches\modules-2\files-2.1\com.facebook.react\react-native\0.71.0-rc.0\7a7f5a0af6ebd8eb94f7e5f7495e9d9684b4f543\react-native-0.71.0-rc.0-debug.aar.
> Java heap space
My first problem is how to resolve this issue? I seem to be unable to find resolutions for this particular issue on the Internet. Obviously it is related to the 'async storage' package and I did update it, however that did not resolve the issue.
Supposedly using the "--warning-mode=all" verbiage should provide links to Gradle to help resolve the issue...however I see none. I also notice in that output mention is given of 'react-native-0.71' however I am using a lower version...not sure if that is related to the issue. Any advice appreciated.
My second question is more general. Why do nonsensical and ridiculous things like this CONSTANTLY happen in React Native? As mentioned, the code worked fine last time I booted up. I can make no changes whatsoever to my code (or minimal ones) and suddenly the code is broken and non-functional...through no fault of my own but relating to some npm package or some other reason (Gradle for example) that has nothing to do with me. I have never seen, nor imagined...that such an unreliable and 'bug-ridden' piece of software could be released to the general public. Why are issues like this consistently occurring in React Native? Is it just incompetence or is there a better answer? I am always dealing with unending frustration and anger due to these practices causing me problems with this particular platform. If somebody could explain why this development 'environment' is riddled with these problems I would be most appreciative.
There will be build failures for Android due to the publish of the React Native version 0.71.0-rc0.
Add this fix to your android -> build.gradle file as follows:
buildscript {
// ...
}
allprojects {
repositories {
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// ...
}
}
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules
If the above doesn't fix your issue then, try the Method 2 mentioned here : React Native Android build failure with different errors without any changes in code for past days due to publish of React Native version 0.71.0-rc.0
The OP seem angry and honestly, i do understand why he is and i doubt why he shouldnt.
I havent run build for 2 days until yesterday, 5th of november when i ran npx react-native run-android then this error was noticed.
I had spent close to 24 hours searching the solution until i stumbled on this question.
This fix according to #Thanhal works for me.
I tweaked my android/build.gradle. Here is the full content of my gradle file and the fix.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
kotlinVersion = '1.6.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// ------ Fix starts here
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// --------- Fix ends here
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"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
I hope this also helps somebody out there.
Recently I fix this issue b update the version of React Native.
I had this 0.68.1 version when I stuck in this error.
you can easily update your version From here
how to update your version From here
after that I clean android Gradle by run this command. go to your project a android directory and run this
./gradlew clean
then comes back to project and run
npm install
after that uninstall the application From your mobile and run your project again
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.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
update distributionUrl
Note: Error may be different but if you are getting any error when taking android build without any changes in code for past two days
My Error - Failed to install the app. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
error Failed to install the app. Make sure you have the Android development environment set up:
Error: Command failed: ./gradlew app:installDebug
-PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* Where: Build file '/Users/....../node_modules/react-native-month-year-picker/android/build.gradle' line: 115
* What went wrong: A problem occurred configuring project ':react-native-month-year-picker'.
> Could not resolve all files for configuration ':react-native-month-year-picker:implementation'.
> Could not resolve com.facebook.react:react-native:+.
Required by:
project :react-native-month-year-picker
> Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:
- debugVariantDefaultRuntimePublication
- releaseVariantDefaultRuntimePublication
All of them match the consumer attributes:
- Variant 'debugVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0:
The build failures for Android was due to the publish of the React Native version 0.71.0-rc0.
Note: Error may be different but this would be the solution if you are getting android build failures without any changes in code for past two days
before trying these methods please revert back every changes you have done : https://stackoverflow.com/a/74371195/10657559
Method 1
Add this fix to your android -> build.gradle file as follows:
buildscript {
// ...
}
allprojects {
repositories {
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// ...
}
}
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules
Method 2
If your gradle doesn't support above, then add this to your android -> build.gradle file as follows:
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
buildscript {
// ...
}
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
// ...
}
Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210
Adding on to the voted answer to do some knowledge sharing.
To reiterate, as #Thanhal has posted, the solution and official explanation can be found here: Android build failures No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.
The biggest question I needed answer following the error was:
After specifying my react-native version in package.json, why does my project still download another react-native version?
I even used npm install --save-exact to ensure I am getting the correct version
The error message I was given left me even more confused:
The class is loaded from ~/.gradle/caches/transforms-3/9a8c596b7e1788d5bad7c80991eefff1/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
e: .../node_modules/expo-modules-core/android/src/main/java/expo/modules/adapters/react/permissions/PermissionsService.kt: (351, 32): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
Somehow Kotlin became an issue for me as well.
Who / What is asking for the latest react-native?
For my case, the issue here wasn't about the version of react-native my project is using. It was about what my libraries are using.
The react-native team had been shipping a Maven Repository inside the NPM package (node_modules/react-native/android/) up till 0.71.0-rc.0. Most of the libraries have their build.gradle configured to reference to this directory. This is done through declaring a custom repository in the libraries' build.gradle:
maven {
url "$rootDir/../node_modules/react-native/android"
}
But in the libraries' build.gradle files, more repositories are declared, which may look like this:
repositories {
maven {
url "$rootDir/../node_modules/react-native/android"
}
google()
mavenLocal()
mavenCentral()
}
Then, the dependency for the library is declared as so:
dependencies {
implementation 'com.facebook.react:react-native:+'
}
Because the "+" as version for the react-native dependency, Gradle will take the latest react-native version from the various declared repositories.
Since in the past react-native was shipped with npm package, the latest which Gradle will always take the react-native in node_modules. However, now that the react-native team is publishing the library to public repositories including MavenCentral, Gradle honours the "+" and take the version on MavenCentral instead.
Why did I get the Kotlin error?
My project uses an older version of react-native and as of version 0.68 react-native started using Kotlin version 1.6.10 (see the change history). So yes, the difference in react-native version would also result in Kotlin error.
Facebook has release bugfix versions for >=0.63. You can upgrade instead of apply the hotfix also.
https://github.com/facebook/react-native/issues/35210
This fix works:
Reason for Failures : The build failures for Android was due to the publish of the React Native version 0.71.0-rc0 to Maven and because of which when the gradle is syncing its picking this 0.71.0-rc0 version of react-native rather then your current version of react-native.
Made it work without upgrading react-native version and by adding this in build.gradle, this works (hermes enabled or not, along with flipper too)
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
final snippet looks like this
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
gradle clean and rebuild after this fix. Then you can react native run android successfully.
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules
Now,
There are some patch releases from react native for different versions, If you dont want to put this fix,
you can update your current react native version to the react native patch version as mentioned here
https://github.com/facebook/react-native/issues/35210
After #react-native-firebase updated their libraries I'm getting this error when running my react native project for android
react-native-firebase_messaging:compileReleaseJavaWithJavac
I googled and tried some changes I found on the internet but nothing worked.
Can anyone help me with this?
My dependencies:
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:28.4.0')
implementation 'com.google.firebase:firebase-messaging'
implementation 'androidx.multidex:multidex:2.0.1'
My buildscript:
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 23
compileSdkVersion = 31
targetSdkVersion = 31
kotlinVersion = '1.5.0'
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
I had the same error while building , i was able to solve it by upgrading my Android Studio .
This error is happened most of the time because of the version of your JDK.
For compile and target SDK version 30, you can use JDK8 and things will work. If you use compile or target SDK version 31 you must upgrade your tools to JDK11 everywhere. It happens frequently that people think they have done that but their gradle build is using an unexpected version of the JDK and still getting 8. All I can say is: update all places to JDK11 and make sure it is actually in use, and in combination with a compile SDK of 31 and a target SDK of 30 (I can't recommend 31 yet unless you test it thoroughly! many modules are still working or support it) things should work
To change the compilesdkversion = 30 to 31, run this command
brew install --cask adoptopenjdk/openjdk/adoptopenjdk11
After upgrade to react-native 0.56(using react-native-git-upgrade ,and update babel-preset-react-native to 5.0.2),
react-native run-ios works fine and app run OK.
But when run react-native run-android, error occur:
/Users/shouhuasun/dev/stage/upgrade-test/mobile-upgrade-test/node_modules/react-native-wechat/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
Other names not found such as:'TextAppearance.Material.Widget.Button.Colored,android:keyboardNavigationCluster',etc.
Other libs like react-native-fetch-blob also got the error.
What's the error?
Thanks!
I got the solution(thanks for Reynald Liandra on facebook React-Native Community Q&A):
The react-native-wechat(same other third libs) android module needs to be compiled using sdk 26 after update to rn v0.56.
Open node_modules/react-native-wechat/android/build.gradle ,
change compileSdkVersion to 26, and buildToolsVersion to 26.0.3
Then run react-native run-android and got the correct result.
If there are several third libs , it is noisy to change several build.gradle files.
And if update any libs version (or yarn add new libs),the node_moudle is refreshed and all changes in build.gradle will lost.
you can force gradle use specified sdk version by this(without modify build.gradle in node_modules anymore):
gradle force build tools version on third party libraries
Make sure your npm version is above 8.0