React native android not compiling with react-native-device-info - android

I'm getting the following error when I try to build the project using $ react-native run-android.
> Task :react-native-device-info:compileDebugJavaWithJavac FAILED
/Users/user/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:31: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
/Users/user/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:838: error: cannot find symbol
#Nullable Object data) {
^
symbol: class Nullable
location: class RNDeviceModule
Note: /Users/ammiel/Desktop/mobile/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILURE: Build failed with an exception.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-device-info:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
I have jetify running postinstall and have
android.useAndroidX=true
android.enableJetifier=true
in my gradle.properties.
Been lurking at many pages/github pages with no success :/ Any help is appreciated!
Other info:
react-native: 0.59.10
react-native-device-info: 5.6.1

I faced the same problem like you!
But I managed to solve it by just adding the dependencies.
yarn add react-native-device-info
Wolla! The app is now running.

for that problem, one way is that you can update the new `react-native-device-
info` to solve the problem.
it releases note give the version which support androidx
2.3.0
feat: AndroidX support (backwards/forwards compatible) (https://github.com/react-native-community/react-native-device-info/pull/733)
fix: isTablet() Android using Google-recommended / robust style (https://github.com/react-native-community/react-native-device-info/pull/730)
the second way is to change the code manually.
the reason is that the android studio does not translate it to androidX API, so it reports errors. so you have to replace them manually or use the newest
the version which had changed to android.
Besides them, you can see this question, it may help you

Related

Task :app:bundleReleaseJsAndAssets FAILED - React Native - Android

Getting this error in my React-Native app when I run on Android using npx react-native run-android --variant=release or generate a Release Build. I tried whatever solutions I found on Stackoverflow and GitHub like - upgrading gradle build tools version, modifying babel.config.js, clean project, --reset-cache, rm -rf node_modules and reinstall, Invalidate and Restart, etc. but none of it solved. It is a blocker since I am not able to generate a build to publish.
I have provided the only stacktrace error available.
> Task :app:bundleReleaseJsAndAssets FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.1/userguide/command_line_interface.html#sec:command_line_warnings
5 actionable tasks: 5 executed
The system cannot find the path specified.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'cmd'' finished with non-zero exit value 1
Another information I noticed is I am getting the above stacktrace when the build execution executes :app:bundleReleaseJsAndAssets and reaches react-native-animated. I tried the solutions suggested from the similar issues reported in react-native-animated but that too didn't fix.
I am not able to find whether the issue is with the package or the local project setup.
Also I noticed that the package doesn't seem to be configured properly in Android. Screenshot attached below for reference. This package alone doesn't have the right arrow.
Library versions:
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-reanimated": "2.1.0"
Gradle info:
classpath("com.android.tools.build:gradle:4.0.1")
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip
Android Studio Version: 4.2.1
Any Suggestions?
While checking this answer I found that the below line was present in my code
project.ext.react = [
nodeExecutableAndArgs : ["/usr/local/bin/node"]
];
My other RN projects doesn't have this line but worked fine. So removing the line nodeExecutableAndArgs : ["/usr/local/bin/node"] fixed the issue.
I was getting a similar issue. After struggling with it for a few hours, realised it was due to babel.
Upgrading babel to latest version helped me resolve this issue.
Hope this helps someone.

Android Execution failed for task ':app:compileDebugJavaWithJavac'. - React Native

I am working on a react native application. when I try to build the applications using react-native run-android the build fails. Here is the output of the error that occurs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app: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
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
BUILD FAILED in 8s
253 actionable tasks: 5 executed, 248 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug
debug Error: Command failed: ./gradlew app:installDebug
at checkExecSyncError (child_process.js:607:13)
at execFileSync (child_process.js:627:13)
at runOnAllDevices (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runOnAllDevices.js:58:39)
at buildAndRun (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runAndroid.js:142:41)
at then.result (/Users/FaisalHussain/mobile/node_modules/#react-native-community/cli/build/commands/runAndroid/runAndroid.js:104:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
The application was on a old version of react native (0.48.x) I have updated it to 0.59.10.
What I have done so far:
used jetifier to resolve issues with the plugins.
checked that the build tools version matches the compile sdk version
checked if the emulator is running.
Hence I have tried everything I could to resolve this but had no luck. Please do guide me on how to resolve this issue. Looking forward to your answers.
make sure you have followed all the necessary steps from the upgrade helper https://react-native-community.github.io/upgrade-helper/?from=0.48.0&to=0.59.10
also i would suggest you to upgrade to v0.60+ because there are breaking changes after v0.59.10.
having said that
before you run the app make sure your gradle is clean
run the following command to clean your gradle cd android && ./gradle clean
then later you can navigate back to your app folder cd .. and try and run again react-native run-android
Looks like your packages not working stable with Android side. It's better be update all packages and react native version to their last stable versions.
If you face with too much error while update, you can create fresh new react native project (with same package name with your current project), install all packages (and their dependencies) and copy your current project's source code to your new project.
Android in React Native does not allow similar packages to reside in the project.
In my case I had react-native-cookies and #react-native-cookies/cookies packages that add similar code to the Kotlin file upon build. This causes issue of similar imports in java JDK.
I removed one and it worked.
SOLVED at the same issue:
My solution was at /android/build.gradle file.
Somehow, the buildscript versions were wrong.
Follow the exact same step of RN documentation and make a totally new & clean project.
And compate the /android/build.gradle file > buildscript & dependencies part.
There should be some version differences.
It matters by your own local env settings.
After changing buildToolsVersion, ndkVersion, classpath, it worked fine again!!
also, remove duplicated libraries, as #Nimantha said.

Trouble Installing Firebase Analytics to my React Native Android version

Ok so I believe I followed these instructions perfectly: https://rnfirebase.io/docs/v5.x.x/installation/android
1) After completing the instructions I get this error: Minimum supported Gradle version is 4.6. Current version is 4.4.
2) I go into gradle-wrapper.properties and change distributionUrl from
https\://services.gradle.org/distributions/gradle-4.4-all.zip
to
https\://services.gradle.org/distributions/gradle-4.6-all.zip
and re-synce
3) When I try to build after this I get the error:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDevMinSdkDevKernelDebugResources'.
In the Java compiler I get the error:
/Users/DJarrin/Work/dev_envs/****/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for details.
I'm pretty lost and would really appreciate just some next steps to solve the issue.

Cannot run React Native Project on Android Device or Simulator with React-Native-Maps dependency

I am currently trying to build and run my project on android but it keeps failing. I followed all the instructions for setting up the android environment correctly, as I am able to get my other applications to work on the simulator. I am using the React native maps dependency on this project, and for some reason whenever I run react-native run-android it crashes with this error:
error: constructor ActionSheetPackage in class ActionSheetPackage cannot be applied to given types;
new ActionSheetPackage()
^
required: FragmentActivity
found: no arguments
reason: actual and formal argument lists differ in length
1 error
:app:compileDebugJavaWithJavac FAILED
Followed by:
What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
I've tried troubleshooting using what can be found on the react-native-maps github page, and none of that seems to work. Does anyone have any ideas?
It turns out that the issue was that there was a dependency that did not work on android. When I npm installed the dependency it also installed it's self in the android portion of the project. Once I removed it from there it worked like a charm.

Ionic v2 Google Maps API Android Build Error: cannot access AbstractSafeParcelable options.compassEnabled(controls.getBoolean("compass"));

I'm trying to implement the Google Maps API using the Ionic docs as seen here.
I'm using the code samples exactly as supplied, but I'm getting the following error:
BUILD FAILED
Total time: 2.748 secs
Error: /path/to/platforms/android/gradlew: Command failed with exit code 1 Error output:
/path/to/platforms/android/src/plugin/google/maps/GoogleMaps.java:479: error: cannot access AbstractSafeParcelable
options.compassEnabled(controls.getBoolean("compass"));
^
class file for com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable not found
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details
Has anyone seen/resolved this issue?
I was able to resolve the issue. While a lot of the suggestions I found revolved around installing missing repositories (you need Android Support Repository, Library, Play Services and Google Repository), I had all that in place. What was missing was that incorrect versioning is specified in project.properties when I used this command to add the plugin:
ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"
In project.properties, I changed this:
cordova.system.library.4=com.google.android.gms:play-services-maps:9.8.0
cordova.system.library.5=com.google.android.gms:play-services-location:9.8.0
To this:
cordova.system.library.4=com.google.android.gms:play-services-maps:+
cordova.system.library.5=com.google.android.gms:play-services-location:+
That resolved the build error.

Categories

Resources