I use react-native-google-fit package to get the steps data about the user. In my case this package works fine in some devices but in some others cant get any data or response from the google-fit API.
I cant understand what is the problem, as I know step recording api of the google-fit is not implemented in default as it is in IOS(health-kit). I implemented bugnsag to track the steps and the process stucks when I call google-fit API to get step samples. No error or exception thrown it just feels like hanging.
If anyone have some idea or solution about it I would be very happy to hear.
package.json
"dependencies": {
"#bugsnag/react-native": "^7.3.2",
"#react-native-community/art": "^1.2.0",
"#react-native-community/async-storage": "^1.8.1",
"#react-native-community/cli-platform-ios": "^4.10.1",
"#react-native-community/datetimepicker": "^3.0.1",
"#react-native-community/masked-view": "^0.1.7",
"#react-native-community/viewpager": "^4.1.0",
"#react-native-firebase/app": "^7.1.0",
"#react-native-firebase/messaging": "^7.1.0",
"#react-navigation/native": "^5.0.9",
"#react-navigation/stack": "^5.1.1",
"axios": "^0.19.2",
"dayjs": "^1.8.33",
"firebase": "^7.14.6",
"localized-strings": "^0.2.4",
"react": "16.9.0",
"react-native": "^0.61.5",
"react-native-device-info": "^5.5.7",
"react-native-document-picker": "^3.5.4",
"react-native-dots-pagination": "^0.1.9",
"react-native-fs": "^2.16.6",
"react-native-gesture-handler": "^1.6.0",
"react-native-get-random-values": "^1.3.1",
"react-native-gifted-chat": "^0.16.1",
"react-native-google-fit": "^0.13.0",
"react-native-highlight-words": "^1.0.1",
"react-native-image-picker": "^2.3.1",
"react-native-onesignal": "^3.9.0",
"react-native-progress": "^4.1.2",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.3.0",
"react-native-vector-icons": "^6.6.0",
"react-native-video": "^4.4.5",
"react-native-webview": "^9.1.4",
"react-navigation": "^4.2.2",
"react-navigation-stack": "^2.2.3",
"react-navigation-tabs": "^2.8.13",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-saga": "^1.1.3",
"rn-apple-healthkit": "^0.8.0"
},
android/build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
classpath('com.google.gms:google-services:4.3.3')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
android/app/build.gradle
defaultConfig {
applicationId "com.xx"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 29
versionName "1.4.18"
multiDexEnabled true
}
dependencies {
implementation project(':react-native-webview')
implementation project(':react-native-vector-icons')
implementation project(':react-native-fs')
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation "com.android.support:support-core-utils:28.0.0"
implementation "com.android.support:appcompat-v7:28.0.0"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
android.xml permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
function that calls google-fit-api
function getStepsForAndroid(startDate, endDate) {
const options = {
startDate: new Date(startDate).toISOString(), // required ISO8601Timestamp
endDate: new Date(endDate).toISOString() // required ISO8601Timestamp
};
return GoogleFit.getDailyStepCountSamples(options)
}
Well I solved the issue.. Still its very weird issue but, first of course its my fault to not check documentation again. Seconds its bad documentation and naming.. Like how you can write READ_WRITE and it can only mean WRITE?
scopes: [
Scopes.FITNESS_ACTIVITY_READ_WRITE,
Scopes.FITNESS_BODY_READ_WRITE,
],
Its very wrong documentation because just after these example it shows how to retrieve steps(as I just followed those). So instead of top I added two extra permissions and the problem is solved.
scopes: [
Scopes.FITNESS_ACTIVITY_READ,
Scopes.FITNESS_ACTIVITY_READ_WRITE,
Scopes.FITNESS_BODY_READ,
Scopes.FITNESS_BODY_READ_WRITE,
],
So this small issue cost me like few weeks which is actually still unlogical because it worked with only two permissions in half of the devices.. Also I google-fit API has problem because in this case this API could fail and we could catch the error and understand that its the problem of lack of permissions.
Related
My React Native App crashes after update target Sdk version and compileSdkVersion 31. It was working version 30. Google play forced us this update. The app crashes on Android 12 version devices. It works on android 10 or 11.
My package.json file:
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#notifee/react-native": "^0.12.2",
"#react-native-community/async-storage": "^1.9.0",
"#react-native-community/checkbox": "^0.5.7",
"#react-native-community/datetimepicker": "^3.0.3",
"#react-native-community/masked-view": "^0.1.9",
"#react-native-community/netinfo": "^9.3.6",
"#react-native-community/picker": "^1.5.1",
"#react-native-community/progress-bar-android": "^1.0.3",
"#react-native-community/progress-view": "^1.2.1",
"#react-native-community/push-notification-ios": "^1.4.1",
"#react-native-firebase/app": "^8.4.1",
"#react-native-firebase/messaging": "7.8.4",
"axios": "^0.21.1",
"date-fns": "^2.28.0",
"moment": "^2.24.0",
"react": "16.13.1",
"react-native": "^0.64.4",
"react-native-animated-pagination-dots": "^0.1.72",
"react-native-autoheight-webview": "^1.6.1",
"react-native-calendars": "^1.1263.0",
"react-native-countdown-circle-timer": "^2.3.7",
"react-native-directory-picker": "^0.0.2",
"react-native-document-picker": "^5.0.0",
"react-native-elements": "^2.1.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-gifted-chat": "^0.16.3",
"react-native-image-picker": "3.2.1",
"react-native-immersive-bars": "^1.0.1",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-month-year-picker": "^1.3.4",
"react-native-paper": "^4.9.2",
"react-native-pdf": "^6.2.2",
"react-native-push-notification": "^5.1.0",
"react-native-reanimated": "2.1.0",
"react-native-redash": "^14.2.3",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.5.0",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^12.1.0",
"react-native-svg-transformer": "^0.14.3",
"react-native-swipe-list-view": "^3.2.3",
"react-native-vector-icons": "^9.0.0",
"react-native-video": "^4.4.5",
"react-native-webview": "^11.23.1",
"react-navigation": "^4.1.0",
"react-navigation-drawer": "^2.3.4",
"react-navigation-stack": "^2.0.16",
"react-navigation-tabs": "^2.5.6",
"react-redux": "^7.1.3",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
"rn-fetch-blob": "^0.12.0"
},
"devDependencies": {
"#babel/core": "^7.11.1",
"#babel/runtime": "^7.11.2",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.2.2",
"eslint": "^7.6.0",
"jest": "^26.2.2",
"metro-react-native-babel-preset": "^0.61.0",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "23.1.7779620"
androidXAnnotation = "1.1.0"
androidXBrowser = "1.0.0"
androidXCore = "1.0.2"
firebaseMessagingVersion = "21.1.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.5.4")
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
I had the same problem 2 days ago.
You have to do these changes:
file: android/build.gradle
Change these versions like these:
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
}
file: android/app/build.gradle
Add implementation 'androidx.work:work-runtime-ktx:2.7.0' dependency.
dependencies {
...
implementation 'androidx.work:work-runtime-ktx:2.7.0'
...
}
EDIT: As of late 2022, version 2.7.1 worked, a few other answers suggest using 2.6.0 too which you may try if they work with your system or not.
`implementation 'androidx.work:work-runtime-ktx:2.7.1'`
file: android/app/src/main/AndroidManifest.xml
Add android:exported="true" to the main activity.
<activity
android:name=".MainActivity"
android:exported="true"
...
>
Also you need to add android:exported="false" to each XML tag that has an intent-filter like services and others.
For example, this is my notification service that has an intent-filter as its child:
<receiver android:exported="false" android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
EDIT: Besides this make sure you are using JDK 11
EDIT: Also if the problem persists delete .gradle folder inside the android folder.
Try add this line inside your dependencies in build.gradle
dependencies {
// ...
implementation 'androidx.work:work-runtime:2.7.1'
}
Maybe is that problem here:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified
Can you also increase your buildToolsVersion to "31.0.0"
Please also make sure that it uses Java 11 and not Java 8.
Dude. Have you tried to update other libraries?
I had same issue and upgrading firebase library version was the solution.
This might be not helpful.
I hope you will fix it.
my issue is when i working with the application everything works fine but when not using the app like 3 or 4 minutes or working just random with application the application does not call any api without error im pretty sure its not the back end or serverside because last version of application works fine without any issue
after api calls doesnt response i turn off wifi and turn on again . everything become normal api successfully called till random moment
packages
"lottie-react-native": "^3.5.0",
"react-native": "^0.63.3",
"react": "16.13.1",
"react-redux": "^7.2.1",
"redux": "^4.0.5",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"#react-native-community/push-notification-ios": "^1.5.0",
"#react-native-community/voice": "^1.1.9",
"react-native-push-notification": "^7.3.1",
"react-native-sqlite-2": "^3.1.1",
"#react-native-firebase/analytics": "^10.6.4",
"#react-native-firebase/app": "^10.8.1",
"#react-native-firebase/messaging": "^10.8.1",
"#react-navigation/bottom-tabs": "^5.9.2",
"#react-navigation/material-top-tabs": "^5.2.19",
"#react-navigation/native": "^5.7.5",
"#react-navigation/stack": "^5.9.2",
androidManifest
android:usesCleartextTraffic="true"
<uses-permission android:name="android.permission.INTERNET" />
build.gradle
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
mavenLocal()
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://www.jitpack.io' }
}
}
and this is my api call
axios.get(url , header).then(async(response) => {
console.log("get => response => " , response)
await onSuccess(response)
}).catch(error => {
console.log("get => error => " , error)
onFailure(error)
})
what i try
i try to change axios , react native , sqlite, react but non of the packages are making this issue
try to changing sdk version to 30,29,28,27 nothing happend
im using fetch methode but not working
then i uninstall node_modules and re install it with powershell but not working again
My app's build fails because of react-native-lock which is a deprecated library. But this happens in android only. It builds and runs successfully on iOS. It gives the following error:
Task :react-native-lock:compileDebugJavaWithJavac FAILED /Users/abc/appname/node_modules/react-native-lock/android/src/main/java/com/auth0/lock/react/LockReactPackage.java:146: error: method does not override or implement a method from a supertype
#Override
^
Note: /Users/abc/appname/node_modules/react-native-lock/android/src/main/java/com/auth0/lock/react/bridge/UserProfileBridge.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
I am stuck over this issue for so long. Any help would be highly appreciated. Its app/build.gradle looks like this:
dependencies {
compile project(':realm')
implementation project(':realm')
compile project(':react-native-vector-icons')
implementation project(':react-native-vector-icons')
compile project(':react-native-lock')
implementation project(':react-native-lock')
compile project(':react-native-firebase')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':react-native-firebase')
}
My package.json dependencies are as follows:
"dependencies": {
"#expo/ex-navigation": "^3.1.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"firebase": "^4.8.0",
"moment": "^2.22.1",
"react": "16.0.0",
"react-moment": "^0.7.0",
"react-native": "0.55.0",
"react-native-firebase": "^5.2.3",
"react-native-loading-spinner-overlay": "^0.5.2",
"react-native-lock": "^0.4.0",
"react-native-popup-dialog": "^0.16.6",
"react-native-step-indicator": "0.0.7",
"react-native-swipe-list-view": "^1.3.1",
"react-native-vector-icons": "^4.4.2",
"react-redux": "^5.0.6",
"realm": "^10.0.0-beta.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
Its project level build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.0.1'
}
The gradle version which I am using is 4.9. The JDK version is 11.
Are you using this depreciated library for Biometrics?
Error while merging dex archives:The number of method references in a .dex file cannot exceed 64K.
The code worked properly before add react-native-firebase/admob. But after adding that library build fails. When i removing the react-navigation built. Why these two libraries cannot use same app?
Here is my app.json file and the build.gradle files.
"#react-native-community/masked-view": "^0.1.6",
"#react-native-firebase/admob": "^6.2.0",
"#react-native-firebase/app": "^6.2.0",
"react": "16.8.6",
"react-native": "0.60.0",
"react-native-gesture-handler": "^1.5.3",
"react-native-image-zoom-viewer": "^2.2.27",
"react-native-indicators": "^0.17.0",
"react-native-modal": "^11.5.3",
"react-native-reanimated": "^1.7.0",
"react-native-responsive-dimensions": "^3.0.0",
"react-native-safe-area-context": "^0.6.2",
"react-native-screens": "^2.0.0-alpha.29",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^2.0.16"
},
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}```
Thank you very much and finally I have fixed the problem. I changed the code as
defaultConfig {
// ...
multiDexEnabled true }
I added multiDexEnabled true line to defaultconfig in android/app/build.gradle file
You have to use Multidex in android if the number of method references in a .dex file exceed 64K . To know how to use Multidex please see it doc
I always encounter this error when I try to run my app on an android device. I followed the RNFirebase instruction step by step to add it to my existing project, but it just doesn`t work.
> Task :app:processDebugGoogleServices
Parsing json file: /Users/myname/Documents/myname/Programmierungen/Project/android/app/google-services.json
> Task :react-native-firebase:compileDebugJavaWithJavac FAILED
/Users/myname/Documents/myname/Programmierungen/Project/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java:50: error: cannot access zzf
promise.resolve(getOrCreateTrace(identifier).getAttribute(attribute));
^
class file for com.google.android.gms.internal.firebase-perf.zzf not found
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
FAILURE: Build failed with an exception
It works fine with ios, just compiling for android does not work.
My /app/build.gradle dependencies: (Yes, I did add the apply plugin at the very bottom)
implementation project(':react-native-firebase')
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.3"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
The android/build.gradle-dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
and allprojects:
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
Other useful information:
"dependencies": {
"babel-preset-react-native": "^4.0.0",
"react": "16.5.0",
"react-native": "^0.57.1",
"react-native-firebase": "^5.0.0"
},
"devDependencies": {
"#babel/core": "^7.1.2",
"#babel/runtime": "^7.1.2",
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.47.0",
"react-test-renderer": "16.5.0"
},
"jest": {
"preset": "react-native"
}
I`m coding on macos Mojave with Java 8.
Thanks for helping!! ':D