Why is my react navigation not working on android? - android

Recently I merged some changes from a colleague and these changes have React Native Navigation setup in it. After installing all the dependencies and setting up everything, When I run the app, I get this error that says
com.app.MainActivity cannot be cast to com.reactnativenavigation.NavigationActivity
Apparently, the error is coming from the following file
react-native-navigation\lib\android\app\src\main\java\com\reactnativenavigation\react\NavigationModule.java
How to reproduce
I am not really sure how to reproduce this error because I don't know what's causing it in the first place. However, the only other unexpected behavior was that my Android Studio or react-native run-android both were failing gradle build when I first added all the required dependencies. The reason for failure was kotlin-android and even though I can confirm that from the build.gradle files of the repository that the required settings exist, still I had to add the relevant required config to my main applications android/gradle.build and android/app/gradle.build
Apparently this solved the issue with now react-native run-android running successful gradle build.
The repository has the following dependencies config
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
Despite the presence of above, my gradle builds were failing and complaining about android-kotlin so I added the following dependencies config to my app's android/gradle.build
classpath('com.android.tools.build:gradle:3.6.2')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
Notice the difference in versions of the gradle (This gradle version came by default with RN 0.62) and kotlin-gradle-plugin. I don't know, but could this be the cause of the issue?
I am using latest version 5.5.1 for #react-navigation/native

I finally figured this out. Actually the problem was being caused by another package that was just added to the project and wasn't setup and being used. The package that was causing the issue was https://github.com/wix/react-native-navigation which I didn't notice it was there and it apparently wasn't properly configured.

Related

Android - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

I am building an android application in which I tried to integrate Firebase Performance Monitoring. In the documentation it is mentioned that I need to add the following line in the project level build.gradle
classpath 'com.google.firebase:perf-plugin:1.3.4'
I have misplaced this dependency in app level build.grade by replacing the classpath with implementation. I have realized the mistake I made and then tried to move the dependency to project level build.gradle file but I am getting the following exception.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
I have even tried removing .gradle folder from the project location and restarted the Android studio but still facing the same issue.
Please help me find the solution.

How can I fix "unexpected element <queries> found in <manifest>" error?

All of a sudden, I am getting this build error in my Android project:
unexpected element <queries> found in <manifest>
How do I fix it?
The Android Gradle Plugin needs to know about new manifest elements, particularly
for the manifest merger process. The plugin has a tendency to get confused if it
sees elements in the manifest merger that it does not recognize, tossing out
build errors like the one in the question.
In this case, Android 11 introduced <queries> as a manifest element, and older versions of the Android Gradle Plugin do not know about that element.
The fact that this occurs from manifest merger means that simply upgrading a dependency
might bring about this error. For example, if you upgrade to the latest
version of com.awesome:awesome-library, and it contained a <queries> element
in its manifest, you might crash with the aforementioned error in your builds,
even without any other changes in your code.
Google released a series of patch versions of the Android Gradle Plugin to address this:
3.3.3
3.4.3
3.5.4
3.6.4
4.0.1
If you are using an existing plugin in the 3.3.* through 4.0.* series, upgrade
to the associated patch version (or higher) from that list, and you should no longer
run into that error (e.g., classpath 'com.android.tools.build:gradle:4.0.1').
If you are using Android Studio 4.1 or higher, with a matching
Android Gradle Plugin (e.g., in the 4.1.* series), you should be fine without
any changes. Those plugin versions were already aware of <queries>.
See this Android Developers Blog post for more.
I had this issue in Flutter, but I believe this solution will work for both Flutter and native Flutter development.
Follow these steps
Read this short blog post to get some understanding: Preparing your Gradle build for package visibility in Android 11
Delete the .gradle folder inside the Android folder, i.e., android > .gradle
In the project build.gradle file, upgrade your class path appropriately based on the blog in the link above, e.g., I upgraded to classpath 'com.android.tools.build:gradle:4.0.1'
Upgrade the distribution URL too. It's in android>gradle>gradle-wrapper.properties file appropriately. E.g., I upgraded it to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
You can invalidate caches and restart your Android Studio. Make sure you have a good Internet connection, because it will download the new Gradle files.
I also suddenly had the same issue two days ago in Android Studio 4.1.1. I solved the issue by upgrading the build Gradle version.
Previous setting in the build.gradle file of the project was:
classpath("com.android.tools.build:gradle:3.5.3")
Current setting:
classpath("com.android.tools.build:gradle:3.5.4")
The issue was gone immediately. :)
Fixing the error is very simple.
Update your Android Studio to the last version
and use the last stable Gradle plugin version.
At the current time, I use Android Studio version 4.1.3 with Gradle Plugin 6.8.2
For use in queries, you should write queries code in out of application tag, not inside application tag.
For more information, see the photo below:
I had this error in the react-native-image-crop-picker library, and I solved this problem by updating the Gradle version as mentioned in previous answers.
It was:
classpath("com.android.tools.build:gradle:3.5.3")
Updated to:
classpath("com.android.tools.build:gradle:3.5.4")
And I ran a:
cd android && ./gradlew clean && cd .. && npx react-native run-android
Then it worked OK.
Due to the new default settings and features for package visibility in Android 11 that need to add <queries>, you must update your Android Gradle plugin.
Google has added some patches to current versions listed in Android Gradle plugin release notes, 4.0.0 (April 2020).
If you want to use a newer version of Android Gradle, you should search for a compatible wrapper from Android Gradle plugin release notes, Update Gradle.
Update your Gradle version to 4.0.1 or later.
File android/gradle/wrapper/gradle-wrapper.properties: update the distribution URL to:
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
File android/build.gradle: update the Gradle plugin:
classpath 'com.android.tools.build:gradle:4.1.2'
to 4.0.1 or later. Here it is 4.1.2 with Gradle version to 6.5 or later.
You can see the distribution chart at How to update gradle in android studio?

NoClassDefFoundError when running unit test with Gradle task

I have a project using dynamic feature module, and I want to run my unit test in feature module via gradle task (for my CI purpose):
./gradlew :feature_product:test
But it always gives me NoClassDefFoundError for tests that have dependencies on classes from the base module:
com.example.android.feature.product.ProductViewTest > on vote change to negative FAILED
java.lang.NoClassDefFoundError: app.BaseView
ProductView class from the feature module extends BaseView from the base module.
Oddly, it succeeds when run in Android Studio, it works fine.
Then I notice something different in the logs, when I run via command line and when I run Android Studio. The first line in the Android Studio is generateDebugSources, something which absent when I run ./gradlew test
Executing tasks: [:lib_ui:generateDebugSources, ...]
How do I fix this? Does Android Studio has different command with the provided command ./gradlew test when I press Ctrl+Shift+R ?
After searching further about this issue, I found it also being reported in the android-test and app-bundle-samples projects and there is also an issue in the issue tracker.
It turns out this issue fixed in the Android Gradle Plugin 4.1.0 as per comment in the issue tracker.
If you don't want to update AGP to 4.1.0 which is still in alpha, adding this to the feature module's build.gradle fixed the issue for me, as per this comment:
testRuntimeOnly(files("$projectDir/../b_app/build/intermediates/app_classes/debug/classes.jar"))
If it is a missing task that you believe is necessary then calling it first like below should do the trick:
./gradlew :lib_ui:generateDebugSources :feature_product:test
I would even go full on and assemble the dependencies if necessary though that might take more time:
./gradlew :lib_ui:assemble :feature_product:assemble :feature_product:test

Unsupported method: InstantRun.getRestartDexFile() - Android Studio

I have Android Studio 2.0 Beta 6
and the Gradle version in build.gradle is classpath 'com.android.tools.build:gradle:2.1.0-beta1'
(I updated it today only, earlier I was at gradle:2.0.0-alpha9).
Now when I try to Run my app I keep getting this Message.
UnsupportedMethodException
Unsupported method: InstantRun.getRestartDexFile().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect.
Alternatively, you can ignore this exception and read other information from the model.
Everything was running fine before the upgrade (including Instant Run).
Please help.
I am posting this as an answer because this solved the problem for me.
I changed the classpath in build.gradle to
classpath 'com.android.tools.build:gradle:2.1.0-alpha3
I did not change anything else/any setting at all, neither did I updated my Android Studio.
Link to the page where I found it.
Had to search a lot. :)
Edit:
Alternatively as pointed out by others,
1. You can either try Upgrading Your Android Studio to 2.1.0 (OR)
2. You can try changing the classpath in build.gradle to
classpath 'com.android.tools.build:gradle:2.1.0
I ran into the same exception
Alternatively, you can ignore this exception and read other
information from the model.
It says there is an alternative solution, so what should we do to ignore this exception ?
OK, upgrading the Android Studio will solve the problem.
I get the trouble on Android 2.1 preview 5.I changed the classpath in build.gradle to
classpath 'com.android.tools.build:gradle:2.0.0'
update the studio to 2.1.0 , will solve your problem
first i have android 2.1 and i have set
then i have set
i also getting that error Unsupported method: InstantRun.getRestartDexFile() - Android Studio
then
Step 1
i have updated android to 2.2 and get that error Unsupported method: AndroidProject.getPluginGeneration() while running project to fix that issue do that
Step 2
refer link -Unsupported method: AndroidProject.getPluginGeneration() while running project
disable instant run Windows & Linux:
Linux:
File -> Settings -> Build, Execution, Deployment -> Instant Run.
Mac:
Android Studio -> Preferences -> Build, Execution, Deployment -> Instant Run.
finally fixed all things and i have successfully run my project.
The problem solved by using:
classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
classpath 'com.google.gms:google-services:2.1.0-alpha3'

gradle fails with Problems reading data from Binary store error

I have a Gradle file that runs the tests. It does not build anything. All it has is a unzip task that extracts all jars in a Gradle configuration into a particular directory and then runs the task of type Test. This test task points the testClasses directory to the location where the previous copy task has extracted the configuration into.
My build fails with the error message:
Problems reading data from Binary store
When I run 'gradle dependencies' it does not show any error/warning
When I run the copy task individually, it runs very well fine.
Only when I run everything it fails with error :
> Could not resolve all dependencies for configuration ':testConfig'.$
> Problems reading data from Binary store in /tmp/gradle8793563212642185736.bin (exist: false)$
I see the file /tmp/gradle8793563212642185736.bin does not exist. What could be the reason for this?
I solved upgrading following packages to last version (06/02/2021), so:
project app-level build.gradle file:
com.google.firebase:firebase-analytics:17.2.2
to
com.google.firebase:firebase-analytics:18.0.2
Project-level build.gradle file:
com.google.gms:google-services:4.3.3
to
com.google.gms:google-services:4.3.5
In my case setting org.gradle.parallel=false flag fixes the issue, but it's not a solution for my project, flag increase CI build time from ~15min to ~45min.
Turns out it was just a network problem for me. Gradle just needed to connect to the internet.
It happened with Flutter development in my case. Apparently, it is not an actual issue and there is no magic fix. Cleaning build file with "Flutter clean" and restarting the command line executer window solved the issue.
I was working with version 5.x earlier and then I upgraded to 6.0.1 and it resolved the issue.
this is how you can upgrade
cd android
./gradlew clean
./gradlew wrapper --gradle-version 6.0.1
./gradlew -v # to download the new version
cd ..
flutter clean
flutter run # might take 15 - 20mins for the first time
There are mainly a few steps to solve this problem.
Go to gradle.properties and set org.gradle.parallel=false and sync. Make sure your sync gradle offline option is off
Start the build with this option. If it's a big project setting org.gradle.parallel=false will take a long time.
Cancel the build repeat the steps setting org.gradle.parallel=true.
Also do not turn on offline build
This solution worked in my flutter project. I solved it by making these changes:
In android level build.gradle file, replace classpath 'com.android.tools.build:gradle:3.5.4' with classpath 'com.android.tools.build:gradle:4.0.1' (basically upgrade the version from 3.5.4 to 4.0.1)
In gradle-wrapper.properties file, replace distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip with distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip (upgrade from 5.6.2 to 6.1.1)
and if you have added classpath 'com.google.gms:google-services:4.3.3' to android level build.gradle file, replace that too with classpath 'com.google.gms:google-services:4.3.5' (upgrade from 4.3.3 to 4.3.5)
In my case the writing problem was there was no enough storage to build the app so I needed to restart my Mac and it finished building successfully.
I know am too late but it might help someone in the future so
Start by upgrading Gradle to the latest version.
Binary store issues reported to GitHub are often fixed right away, especially if they include a Minimal, Reproducible Example.
If upgrading didn't work, it can be useful to run the task again with Performance options disabled:
--no-parallel
--no-configure-on-demand
Next please find an existing issue or open a new one so it can be fixed in future versions. These things are all helpful:
Minimal, Reproducible Example
Build Scan
Smallest change that introduced the problem (e.g. worked on 5.5, but not 5.6)
I ended up here after publishing an artifact to mavenLocal().
I tried a lot but in the end what helped me was:
Upgrading gradle from 6.3 to 6.9
./gradlew wrapper --gradle-version 6.9
Hope this saves me half an hour next time this occurs.
Thanks to Cedric's hint, stopping gradle offline mode and make it online, fixed the issue for me

Categories

Resources