I have a react native application ready for the release, after following the android documentation and have added flavors to the product
flavorDimensions "version"
productFlavors {
free {
dimension "version"
applicationId 'com.my-app.free'
}
}
The command react-native run-android fails the gradle build with the following error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':react-native-appboy-sdk:transformClassesWithDexForDebugAndroidTest'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
Considerations
If I comment the flavor in the gradle file the command runs without any problem.
Even with this error, I can assemble the apk without any errors using the command ./gradlew assembleRelease.
I can run the app using the android studio run configuration without any errors, this seems to be related to adding flavors and running with the react-native command
Please add below code in your android/build.gradle file, hope it will help you:
android {
dexOptions {
preDexLibraries = false
}
}
Also try below command if above not working:
react-native run-android --variant=developmentDebug
Related
I'm trying to run react-native run-android but receive the following error:
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:26: error: package com.facebook.react.module.annotations does not exist
import com.facebook.react.module.annotations.ReactModule;
^
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:34: error: cannot find symbol
#ReactModule(name = AsyncStorageModule.NAME)
^
symbol: class ReactModule
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-community_async-storage:compileDebugJavaWithJavac'.
> 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 1m 16s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Things I've tried:
Reinstall node_modules
cd ./android and then ./gradlew clean
But none of them seems to work. I am glad to hear your suggestion, thank you in advance!
My version:
react-native-cli: 2.0.1
react-native: 0.61.4
android gradle plugin: 3.5.3
gradle: 5.4.1
Try with below command
react-native link #react-native-community/async-storage
feel free for doubts
Try the following solutions.
Uninstall Node Modules
Clean Gradle (cd android && gradlew clean)
now install back your modules (yarn install)
if this does not help try upgrading your packages.
yarn upgrade --pattern react-native
Open the AVD Manager and try to start your phone emulator with Cold Boot, then close all applications. Clean and compile your application again, it must work now.
Sometimes even when you clean your application, your emulator get stuck.
Annotations usually has something to do with Jetpack migrations
Try using this Jetifier tool
Just make sure to run npx jetify at the project root.
Using sudo solved the issue in my case. sudo react-native ..., sudo ./gradlew ... etc.
You can try to add this to your android/build.gradle file
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 {
// NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
}
}
}
mavenCentral()
mavenLocal()
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")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
react-native run-android failed after linking with react-native-ble-plx
Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED
This is a newly created app with react-native init, didn't change anything except the min sdk.
Already tried to clean project, set min sdk to 18, tried to build with android studio to get more specific error but still can't understand where is the problem coming from.
The Error i get:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 2 executed, 10 up-to-date
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/converter/RxBleScanResultConverter.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/wrapper/Characteristic.java:5: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
full logs here :
https://pastebin.com/NJAmjUJm
Can supply more information if needed.
Thank you
This issue is similar to this issue.
As mentioned in #Kreator answer it is related to some packages that are not converted to AndroidX.
To fix this issue you can use jetifier.
I have the same issue mentioned in the question and these steps solved it and application run again.
First, use Android Studio's refactoring tool to convert your app re: the Android developer docs
npm install --save-dev jetifier
npx jetify
npx react-native run-android (your app should correctly compile and work)
Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again)
Problem was that i was using Android Studio Preview, and with that AndroidX and more unsupported packages.
I HAD THIS SAME ISSUE.
"Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task
':react-native-ble-plx:compileDebugJavaWithJavac'.
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 54s
error Failed to install the app. Make sure you have the Android
development environment set up:
https://reactnative.dev/docs/environment-setup.
Solution
this was my build.gradle project:
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "21.4.7075529"
kotlin_version = "1.6.0" // Update this to your version
}
repositories {
google()
mavenCentral()
}
...
}
I changed the some version to as following:
compileSdkVersion = 29
targetSdkVersion = 29
And now the Build is successful!
I've been struggling with this all day.
I did the same thing that the repo says.
I ran:
npm install react-native-camera --save
react-native link react-native-camera
The output said that everything was linked correctly.
But when I do:
react-native run-android
I get this error:
\MainApplication.java:6: error: package org.reactnative.camera does
not exist import org.reactnative.camera.RNCameraPackage;
^
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
That's not the entire error, I think that's just the most relevant part of it.
Any hand?
Insert the following lines inside the dependencies block in android/app/build.gradle:
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
compile 'com.android.support:exifinterface:25.+'
compile ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
You may need to use different exifinterface versions, e.g. 27.+ instead of 25.+.
https://github.com/react-native-community/react-native-camera
4th step on manual installation on android.
Any ideas what this error means?
When I try and run, npm run playground-android, I get the error.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugResources'.
java.io.IOException: Could not delete path 'C:\sites\ReactMatt\lower-your-drinking\android\app\build\generated\source\r\debug\org\webkit'.
Any ideas?
I one had similar issues. Below is how I fixed it.
cd android //Navigate into the android folder from the root directory
./gradlew clean // Run this
I hope it helps
On windows
i resolved by
1. cd android
2. ./gradlew clean
Try to close Android Studio while building through the CLI
I had this same problem but gradlew clean did not resolve issue until I removed the android and ios folders from my project and then used these commands;
react-native eject
react-native link
react-native run-android
good luck.
This works for me!
1) Navigate to android : cd android
2) Then run this command: ./gradlew clean
In your project,
Navigate to android => cd android
Then, run this command => ./gradlew clean
Then, open your project's Android kloser from Android Studio and Build Gradle
I am running a React-Native app but when I try to gradlew installDebug in the android directory I get a build failure. Here is the info I get when I use:
gradlew installDebug --info
`BUILD FAILED
Total time: 1.118 secs
Stopped 0 compiler daemon(s).
Received result CommandFailure[value=org.gradle.launcher.exec.ReportedException: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring project ':app'.] from daemon DaemonInfo{pid=4326, address=[4c8a3b8f-5957-4911-b262-0e36824d2139 port:54258, addresses:[/0:0:0:0:0:0:0:1, /127.0.0.1]], idle=true, context=DefaultDaemonContext[uid=dbec8c34-89ba-4872-9077-12b4b3ff38a0,javaHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home,daemonRegistryDir=/Users/d0ntg0m0ng/.gradle/daemon,pid=4326,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]}.`
This is the error I get when I run gradlew installDebug without --info
`android [router] :> ./gradlew installDebug
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
Cannot evaluate module react-native-couchbase-lite : Configuration with name 'default' not found.`
"react-native": "^0.15.0", is the version of react-native I am using.
this is the repo that the project is fork from
I am trying to setup the app to my genymotion emulator but the build never finishes.
I have already run the commands to react-native start and set up the sync to the couchbase lite server. Not sure if this is relevant info. I am fairly new to native development and I have no idea where to start with trying to debug this.
include ':app'
include ':react-native-couchbase-lite'
project(':react-native-couchbase-lite').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-couchbase-lite/android')
check the file path