I did all the prerequisites for using react native on Windows and created the project by executing the npx react-native init myplatform command but I encountered the following error after the npx react-native run-android command and couldn't believe my eyes because some time ago it was running on the system without any problems.
react native version : 0.63.4
In my case i'm solved with:
tns install
miss gradlew shell script
miss debug.keystore (optional)
match downloaded SDK version, if NDK needed, do the same process
example build.gradle
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
kotlin_version = "1.3.50"
kotlinVersion = "$kotlin_version"
androidXCore = "1.6.0"
This error is because of your gradlew.bat file is corrupt try add new one then try again.
you can find new file from react native github
gradlew.bat
try this!
Related
I install Notifee package using yarn,
yarn add #notifee/react-native
After I run it,
yarn start
yarn run android
Throws an error like this,
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':notifee_react-native:compileDebugJavaWithJavac'.
I'm struggling to implement notifications in my React Native project. Really appreciate it if somebody could help me. Thanks.
As in v 6.0.0 added Android 13 support the compiledSdkVersion and targetSdkVersion should be changed to 33.
In your project android/build.gradle change,
compileSdkVersion = 33
targetSdkVersion = 33
More reference,
https://www.youtube.com/watch?v=Fxzi8Ug9NUA&ab_channel=CodewithMishen
In case if someone doesn't want to change the compileSdkVersion (maybe because other library will have compileDebugJavaWithJavac error) then they can try:
npm install --save #notifee/react-native#5.7.0
and keep the compileSdkVersion the same as before
Android Studio SDK Version:- 29.0.2
While Running npx react-native run-android command got error
startup failed:
General error during semantic analysis: Unsupported class file major version 60
java.lang.IllegalArgumentException: Unsupported class file major version 60
Error Image
build.gradle file description -
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
}
It supports Java 16 from grade 7.0. However, the gradle version supported by the latest version android gradle plugin (4.2.0) is 6.7.1 as of now.
Lowering the JDK version to 16 can solve the problem.
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 just got a react native project and I am trying to run it. When I run:
react-native run-android
, this is my output.
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Checking the license for package Android SDK Platform 27 in C:\Users\oriont\AppData\Local\Android\Sdk\licenses
Warning: License for package Android SDK Platform 27 not accepted.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Users\oriont\AppData\Local\Android\Sdk
* 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 1s
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
Command failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:637:11)
at Object.execFileSync (child_process.js:655:13)
at runOnAllDevices (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
I have followed all of the directions on the facebook getting started page, but this error keeps popping up. When I run it, I have my AVD running, which is on Android 9. From there, I tried to accept the licenses.
C:\Users\oriont\AppData\Local\Android\Sdk\tools\bin>sdkmanager.bat --licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
And I don't know what to do from here. I tried expo and it was another rabbit hole... Someone please help! Thanks!
Android Studio > Preferences > Appearance & Behavior > System Settings > Android SDK
Tick the latest Android versions, click Apply.
It's at this point where Android will ask you to agree to its license(s) and the updated version(s) will be installed.
From Here GitHub
I read an answer (Thank you) but it sadly didn't work. I now think that the licenses aren't the problem anymore. I had realized that the project wanted android 27 and I had android 28 installed, so I tried downgrading to android 27. That didn't work, so I just upgraded (I think) the project to android 28 by changing ext in android/build.gradle to:
ext {
buildToolsVersion = "28.0.0"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 26
supportLibVersion = "28.0.0"
}
and add this to android in android/app/build.gradle
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
I also had java 10.0.2 installed and I downgraded to java 8. (not sure if that made a difference)
Anyways I hope this helps people get their old projects up to date!
I'm looking to override the command react-native run-android and I can't find a solution.
I'm working with different variants and schemes for my apps, and by default, run-android launch installDebug whereas it doesn't exist in my project. (same issue for iOS)
Thanks,
Best.
You can add a command to the script-part in your package.json.
Then you can run the command via npm run <command>.
"scripts": {
//...
"run_app": "react-native run-android"
}
Entering npm run run_app would execute the given command.
If you have few flavors you can set it with --varint flag.
Say we have these:
productFlavors {
dev {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xyz.dev'
...
}
beta {
minSdkVersion rootProject.ext.minSdkVersion
...
}
}
You can run it using this command
--variant=<productFlavour><BuildType>
So to run the dev version in debug mode, we use
react-native run-android --variant=devDebug --appIdSuffix=dev
And to build the release version, use the command
assemble<ProductFlavour><BuildType>
Example for building a beta release
cd android && ./gradlew assembleBetaRelease
I found this medium post with a detailed explanation hope it helps.
https://medium.com/#ywongcode/building-multiple-versions-of-a-react-native-app-4361252ddde5