React Native: Failed to install the app. Could not find or load main class org.gradle.wrapper.GradleWrapperMain - android-studio

I recently started my React Native journey and hit a snag before I could even start to code. I followed the guide by Facebook on how to set up your environment for a React Native project, though I installed java SDK, python and node manually instead of through chocolatey. Installing the react native application on my system went smoothly but when I try to run on my Android Emulator by using the command react-native run-android, I run into the following Error message.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
The system cannot find the path specified.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
The system cannot find the path specified.
Note: I have not made any changed in any file nor deleted anything
Steps to reproduce
Run the command react-native init AwesomeProject
cd AwesomeProject
Ensure Emulator is running then start Metro Bundler with react-native start
Run command react-native run-android in a separate terminal to receive error
Steps taken to resolve
I have tried following multiple issues and queries of others with similar problems to no avail
I tried re-installing everything from scratch to no avail, and creating a new project but the same message appears after hours of re-installation
One person suggested running gradle wrapper inside the project folder, but that too made no difference
Another suggested that a file name gradle-wapper.jar would be missing, but its there in the project folder
I tried loading the Android folder of the react native project in my Android Studio, the gradle starts building but there is still no success when the gradle is built
Packages Installed
Node V12.18.2
Java SDK V8
Python 2.7
Android Studio SDK [Android 10.0 (Q)]
Android SDK Build-Tools (Installed)
Android Emulator (Installed)
Android SDK Platform-Tools (Installed)
Intel x86 Emulator Accelerator (HAXM Installer) (Installed)
Please let me know if any further information is required to understand my problem. Thanks!

Related

Getting "ANDROID_HOME environment variable is not set" when running "ns run" & "ns doctor android"

I'm using MacOS. I've already used Android Studio and Xcode to one of my react-native projects before. I am now learning SvelteNative. As I've started following the docs here and here, and got onto the step where I need to run ns doctor android I get this error:
zeddrix#Zeddrixs-MacBook-Pro todoapp % ns doctor android
✔ Getting environment information
TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies.
There seem to be issues with your configuration.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.1.2 version and is up to date.
⚠ Update available for component #nativescript/core. Your current version is 7.0.0 and the latest available version is 8.1.3.
⚠ Update available for component #nativescript/android. Your current version is 7.0.0 and the latest available version is 8.1.1.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Xcode is installed and is configured properly.
✔ xcodeproj is installed and is configured properly.
✔ CocoaPods are installed.
✔ CocoaPods update is not required.
✔ CocoaPods are configured properly.
✔ Your current CocoaPods version is newer than 1.0.0.
✔ Python installed and configured correctly.
✔ The Python 'six' package is found.
✔ Xcode version 13.0.0 satisfies minimum required version 10.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ WARNING: The Android SDK is not installed or is not configured properly.
You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later.
Run `$ sdkmanager` to manage your Android SDK versions.
✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
Cannot read property 'toLowerCase' of null
zeddrix#Zeddrixs-MacBook-Pro todoapp %
I get this too when running ns run:
zeddrix#Zeddrixs-MacBook-Pro todoapp % ns run
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✖ The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.
To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ WARNING: The Android SDK is not installed or is not configured properly.
You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements
✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later.
Run `$ sdkmanager` to manage your Android SDK versions.
✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
Your environment is not configured properly and you will not be able to execute local builds.
Verify that your environment is configured according to the system requirements described at
https://docs.nativescript.org/environment-setup.html#macos-android.
zeddrix#Zeddrixs-MacBook-Pro todoapp %
I tried uninstalling Android studio and then installing it again because I was thinking it could be the cause but still nothing. I didn't do this with Xcode because it takes very long to get it downloaded and since this error about ANDROID doesn't seem to have a connection about Xcode.
Then I searched for solving the issue about the missing or misplaced ANDROID_HOME environment variable. This article helped me.
So I ran:
cd ~/
touch .bash_profile
open -e .bash_profile
And then put these in .bash_profile:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
But still got nothing... I don't know how to solve the next warnings below this, too. Help.
After days of waiting and researching, I've read the official Android Studio docs for setting env vars. And saw that:
(ANDROID_SDK_ROOT) Sets the path to the SDK installation directory. Once set, the value
does not typically change, and can be shared by multiple users on the
same machine. ANDROID_HOME, which also points to the SDK installation
directory, is deprecated. If you continue to use it, the following
rules apply: If ANDROID_HOME is defined and contains a valid SDK
installation, its value is used instead of the value in
ANDROID_SDK_ROOT. If ANDROID_HOME is not defined, the value in
ANDROID_SDK_ROOT is used. If ANDROID_HOME is defined but does not
exist or does not contain a valid SDK installation, the value in
ANDROID_SDK_ROOT is used instead.
I know that I can do this for ANDROID_HOME. But since the docs says here that it's deprecated, I've decided to do this on the ANDROID_SDK_ROOT instead. I opened up my Terminal and ran this:
set ANDROID_SDK_ROOT=Users\zeddrix\Library\Android\sdk\
It seemed like the CLI is waiting for another command after I did this so I then did this:
export ANDROID_SDK_ROOT=/Users/zeddrix/Library/Android/sdk
If that doesn't work, try this:
set ANDROID_HOME=Users\zeddrix\Library\Android\sdk\
Then:
export ANDROID_HOME=/Users/zeddrix/Library/Android/sdk
The error about this ANDROID_HOME has gone. Now I only had one error left to solve:
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=30'.
Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly.
The first comment in this question helped me through. I went to SDK Manager of my Android Studio > SDK Tools and then as #Kevin McCarpenter said:
"Uncheck (check actually) 'Show Package Details' and then you can select
a lower version. If you're not building for android 12 (and you
probably aren't yet), you can uncheck '31.0.0' and check '30.0.3'.
After that, go into the build.gradle in your app and change
buildToolsVersion '31.0.0' to buildToolsVersion '30.0.3'"
Then I ran ns run android (as said when I run ns run --help) and it finally worked!

Error when archiving IOS app in react native with error : ld: library not found for -lFBReactNativeSpec

I cannot build my IOS app. the error says
Showing Recent Errors Only
Library not found for -lFBReactNativeSpec
After investigation, i found that the new version react-native "react-native": "^0.64.0" move the react FBReactNativeSpec folder from
../node_modules/react-native/libraries/FBReactNativeSpec"
to
../node_modules/react-native/React/FBReactNativeSpec"
i have checked the build settings header paths, check the react-native pod script file, and the file FBReactNativeSpec is included
the strange thing is that the application is running normally in debug version and not when trying to product/archive for test flight
I got the same problem, when updating an app that had been generated for IOS 13, when updating to IOS 14 the XCode informed that the minimum for the build should be version 12, and it was for 9.0, trying to generate the build in version 9 and 10, these lib not found errors will occur, when accepting the minimum for version 12 the build was generated without errors.
The "library not found" errors occur most of the time because installing the react-native node package and running "pod install" is often not enough.
The error should go away after running a clean build in xcode using the xcworkspace file. After that, running "npm run ios" or "npm start" in the termal should work again.

Android studio is giving the following error when I am trying to build a ionic project "Gradle sync failed: Sync failed: reason unknown"

I am trying to build a ionic project in Android studio on Ubuntu 20.04 . I am using the command ionic capacitor build then android studio opens up as expected then it shows this error Gradle sync failed: Sync failed: reason unknown. I am unable find a solution for this particular gradle sync error. I have reinstalled Ubuntu and other things but still the problem persists.
In my case, a fresh install of Android Studio resulted in Android 31 being the only SDK available but the project was targeting Android 30. I went to Tools > SDK Manager and made sure the appropriate version of Android SDK was installed and available. After restarting, and allowing the gradle sync to complete I was able to build/run the app on a virtual device, etc.
Here is what I found
This is the screenshot thanks for helping.
Capacitor lets you manage your own Android project. Like any IDE-backed project, sometimes things get so out of sync that the only solution is to rebuild the project.
To do this, follow these steps:
Copy any source code you created (such as Java files in app/android/src, manifest files, or resource files) into a safe location outside of app/android.
Next, make sure you are running an updated version of the Capacitor CLI:
npm install #capacitor/cli#latest
Remove the android directory:
rm -rf android/
Re-create the Android app from Capacitor:
npx cap add android
Copy your saved source files back into the project.
Check the error log. You should find something like "Module: 'mobile' platform 'android-30' not found" or something similar. Click Tools > SDK Manager and download the appropriate Android SDK Platform package.
on top right you will see option to view log file upon clicking there you will redirect to file manager and open idea file there
example :
open idea file and scroll down you will see actual issue.
In my case android sdk 31 was not installed.
I installed android sdk 31 from File>Settings>Apprearance and behaviour>system settings>android sdk and install required android sdk and rebuild the project.
accord to my observation in most cases you get this error because you have not required sdk installed in your system.

Flutter compile error inside Android Studio

I had been developing a flutter mobile app for a couple of months and all was good. I just came back to the project and a few things (flutter, dart, android studio etc) upgraded. Now I can't compile my app. I created a new flutter app (the default example) and that won't compile either.
The error I'm getting is :
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings remapped class cache for bq3hllkgb26p0nrblf5gh8d37 (C:\Users\Paul\.gradle\caches\5.6.2\scripts-remapped\settings_cbd968glg60byp9f5t6vvdlee\bq3hllkgb26p0nrblf5gh8d37\settings8410a2d21ed2f87c8a0398566330ee52).
> Could not open settings generic class cache for settings file 'D:\Apps\Flutter\Examples\flutter_app\android\settings.gradle' (C:\Users\Paul\.gradle\caches\5.6.2\scripts\bq3hllkgb26p0nrblf5gh8d37\settings\settings8410a2d21ed2f87c8a0398566330ee52).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 57
I am running:
Flutter 1.20.2
Dart 2.9.1
Android Studio 4.1
Java 1.8.0_261
JVM 13.0.2
Gradle 6.7
Windows 10
Try running
flutter stable
flutter clean
flutter downgrade
cd <Your App Folder>
and then
flutter run
in command line
I ended up completely removing Flutter from my system and then re-installed it. This fixed everything.

React Native project runs in Android Studio but not from terminal

I am new to both react-native and JS. I am facing this issue where when I run my project on device using Android Studio 'run', it works. But when I try to run it using "react-native run-android" command, it doesn't run with following error:
What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
Could not create service of type AnnotationProcessorDetector using JavaGradleScopeServices.createAnnotationProcessorDetector().
This error also shows when I try to build debug Apk.

Resources