react-native-maps production: app crashes when opening basic <Mapview/> - react-native

I am unable to integrate react-natives-maps in a production build as I am unsure how to set it up with expo and react native 0.61.
Am I supposed to create a android/build.gradle file to make this work? Till now I wasn't needing this file as everything is handled by expo. I also don't have any other files in the android/ folder. This is the build.gradle that I have added:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'de.undercouch:gradle-download-task:4.0.0'
implementation(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-maps:10.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
but I am actually unsure whether this file is used at all when I run expo build:android.
I have created the gradle file according to the installation instructions here, specifically for the 0.61 version.
When I open the APK-file after running expo build:android the screen simply crashes which make me think somehow react-native-maps is not linked properly. I am not getting any error as the app simply restart.

Depending on how you have created your react-native project with Expo will determine what folders are available and how you install dependencies.
By default Expo abstracts away the native iOS and Android code so that you do not have to worry about it.
As you project does not have and ios and android folders, this means that you are using a managed workflow which means you cannot install dependencies that add native code.
Expo provides MapView which is what you are looking for. You can install it by following the instructions here.
Basically, as you are using a managed workflow, you should use:
expo install react-native-maps
You shouldn't be adding ios or android folders to a managed workflow application as that won't do anything.

Related

Fix for older react-native (< 0.63)

The fix above only works on gradle 6.2 and higher. Older react-native used older gradle.
You may determine your gradle version by looking in your /android/gradle/wrapper/gradle-wrapper.properties file.
If you are on an older version of react-native (for example 0.63 or earlier) that uses gradle version 6.1 or below, you must use a different workaround as gradle 6.1 does not support exclusiveContent.
Add this in the allprojects area of your android/build.gradle file.
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.65+, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
Instead of using exclusiveContent, the hotfix must force the version of React Native. The recommended hotfix shells out to node to read your current version of react-native. If you hard code the version of react-native, when you upgrade your project in the future, your build will fail if you forget to remove this hotfix.
Note that this fix is fragile as the location of your package.json could be different if you are in a monorepo, and node might not be available if you use a node package manager like nvm.
fix issue when use react-native < 0.63

How to clear gradle to reinstall npm package (React Native Android)

I have an issue with an npm package react-native-video where it says 'no variant found for :react-native-video.' I've tried uninstalling and reinstalling, deleting node_modules and yarn.lock and clearing gradle, invalidating caches and restarting Android Studio, and any permutation of the above things.
The app builds and syncs perfectly find without react-native-video, but any time I reinstall it and add the files back in the app.gradle and other files (per the installation instructions) it gives me the same error. Has anyone had this issue before, and how do you fix it? I'm assuming it's an Android Studio/Gradle issue, but I'm at a complete loss as to how to fix it.
Please check your version of React Native and react-native-video.
In my case, I use React Native 0.64.1 and react-native-video 5.1.1, and it works well.
Other solution
Assuming you are on a later version of React Native, In android/build.gradle you need to add jcenter(), in this case best to be explicit and only include what is necessary:
...
allprojects {
repositories {
... other repositories
jcenter() {
content {
includeModule("com.yqritc", "android-scalablevideoview")
}
}
}
}

How to add onesignal to expo project

I want to add onesignal push notification to expo project.
However, i need to add something like this :
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
to
app/build.grandle
but expo project doesnt include build.grandle folder
how can i handle this
The short answer is you can't.
Checkout The only supported third-party push notification service is the Expo notification service.
If you want to use OneSignal with expo, you have to eject to the bare workflow. Here's a link to OneSignal documentation: Must eject to bare workflow

Cordova CLI build gradle error : java.lang.NoClassDefFoundError: com/android/build/gradle/internal/ToolingRegistryProvider

i follow steps based on cordova installation instruction
here.
but when i want to build a hello project, it gives me following error :
java.lang.NoClassDefFoundError: com/android/build/gradle/internal/ToolingRegistryProvider
does anyone knows what's went wrong?
additional info :
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed Google Inc.:Google APIs:24,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:15,android-26,android-25,android-24,android-23,android-22,android-21,android-19,android-15,android-14
Gradle: installed D:\gradle\gradle-4.4.1\bin\gradle
https://i.stack.imgur.com/j9JFA.png
#kmno, try this in your build.gradle to see if it works. (Android dependencies)
allprojects {
repositories {
google()
jcenter()
}
}

React Native: Android Studio doesn't automatically bundle when building

I am building a react native application and we're doing the production release.
I noticed that everything works in my iOS app (there's a build phase that generates the offline bundle) but when I run the release build in Android Studio, my app builds but it crashes because it can't find the bundle.
I was able to resolve my own question:
We changed our build types/flavors to match our desired configuration.
The react.gradle file that comes with React Native has a configuration for Debug and Release, these are the common build tasks in a native application. BUT once you change things up you need to tell the react library in android whether or not you want it to bundle for you.
You can find this in your app's build.gradle (under
./android/app/build.gradle). There's an entire block of guidelines commented out that explain you what to do.
In my case I had to add the following code before apply from: "../../node_modules/react-native/react.gradle"
ext.react = [
bundleInNameDebug: false,
bundleInNameBeta: true,
bundleInNameRelease: true
]
NameDebug, NameBeta, NameRelease are all custom BuildTypes/BuildFlavors I have configured.
If you have the signing configuration, it should build a apk for testing when you run react-native run-android --variant=release with the offline bundle. If you want to make a release build for Playstore, run ./gradlew assembleRelease inside the android folder.
You can find more info here