StasDoskalenko / react-native-google-fit

A React Native bridge module for interacting with Google Fit
MIT License
335 stars 209 forks source link

Task :react-native-google-fit:compileDebugJavaWithJavac FAILED #204

Closed zinaida2mc closed 3 years ago

zinaida2mc commented 3 years ago

I upgraded to 0.16.1 and now while I'm trying to run the project but I'm getting those issues:

/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:78: error: cannot find symbol
                .read(DataType.TYPE_SLEEP_SEGMENT)
                              ^
  symbol:   variable TYPE_SLEEP_SEGMENT
  location: class DataType
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:77: error: cannot find symbol
                .includeSleepSessions()
                ^
  symbol:   method includeSleepSessions()
  location: class Builder
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:84: error: cannot find symbol
                        .addDataType(DataType.TYPE_SLEEP_SEGMENT, FitnessOptions.ACCESS_READ)
                                             ^
  symbol:   variable TYPE_SLEEP_SEGMENT
  location: class DataType
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:134: error: cannot find symbol
            sleepStage.putInt("sleepStage", dp.getValue(Field.FIELD_SLEEP_SEGMENT_TYPE).asInt());
                                                             ^
  symbol:   variable FIELD_SLEEP_SEGMENT_TYPE
  location: class Field
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:148: error: cannot find symbol
                .setDataType(DataType.TYPE_SLEEP_SEGMENT)
                                     ^
  symbol:   variable TYPE_SLEEP_SEGMENT
  location: class DataType
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:162: error: cannot find symbol
                            .setField(Field.FIELD_SLEEP_SEGMENT_TYPE, stage.getInt("sleepStage"))
                                           ^
  symbol:   variable FIELD_SLEEP_SEGMENT_TYPE
  location: class Field
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:170: error: cannot find symbol
                .addDataType(DataType.TYPE_SLEEP_SEGMENT, FitnessOptions.ACCESS_WRITE)
                                     ^
  symbol:   variable TYPE_SLEEP_SEGMENT
  location: class DataType
/Users/***/node_modules/react-native-google-fit/android/src/main/java/com/reactnative/googlefit/SleepHistory.java:169: error: cannot find symbol
                .accessSleepSessions(FitnessOptions.ACCESS_WRITE)
                ^
  symbol:   method accessSleepSessions(int)
  location: class Builder
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
8 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-google-fit:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

I've already cleaned build, Gradle, node_modules and don't know what to do next

aboveyunhai commented 3 years ago

which react-native version do you use? Do you use react-native link on this package in the past? I believe this kind of problems always come from your android build gradle setting.

zinaida2mc commented 3 years ago

RN version is 0.63

No, I chose manual installation

I was trying to update package since play beta demanding targetSdkVersion starting from 29 and app crashes on getting steps count because of missing permission of activity_recognition

aboveyunhai commented 3 years ago

Can you paste your build.grade setting? I can test it out right now to see if i can reproduce the issue

zinaida2mc commented 3 years ago
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: "com.google.firebase.firebase-perf"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

rootProject.ext.set("authVersion", "18.0.0")
rootProject.ext.set("fitnessVersion", "18.0.0")

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "app.id"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 63
        versionName "1.1.2"
        multiDexEnabled true
    }
    signingConfigs {
        debug {
            if (project.hasProperty('DEVELOPMENT_KEYSTORE_FILE')) {
                storeFile file(DEVELOPMENT_KEYSTORE_FILE)
                storePassword DEVELOPMENT_KEYSTORE_PASSWORD
                keyAlias DEVELOPMENT_KEY_ALIAS
                keyPassword DEVELOPMENT_KEY_PASSWORD
            }
        }
        staging {
            if (project.hasProperty('STAGING_KEYSTORE_FILE')) {
                storeFile file(STAGING_KEYSTORE_FILE)
                storePassword STAGING_KEYSTORE_PASSWORD
                keyAlias STAGING_KEY_ALIAS
                keyPassword STAGING_KEY_PASSWORD
            }
        }
        release {
            if (project.hasProperty('PRODUCTION_KEYSTORE_FILE')) {
                storeFile file(PRODUCTION_KEYSTORE_FILE)
                storePassword PRODUCTION_KEYSTORE_PASSWORD
                keyAlias PRODUCTION_KEY_ALIAS
                keyPassword PRODUCTION_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        debug {
            debuggable true
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
        staging {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            matchingFallbacks = ['release']
            signingConfig signingConfigs.staging
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-google-fit')
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

    implementation fileTree(dir: "libs", include: ["*.jar"])

    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    if (enableHermes) {
            def hermesPath = "../../node_modules/hermes-engine/android/";
            debugImplementation files(hermesPath + "hermes-debug.aar")
            releaseImplementation files(hermesPath + "hermes-release.aar")
        } else {
            implementation jscFlavor
        }

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
aboveyunhai commented 3 years ago

I wonder about this one defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion }

I believe it comes from your android/build.grade

zinaida2mc commented 3 years ago
buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 27
        compileSdkVersion = 29
        targetSdkVersion = 29
        androidXCore = "1.0.2"
    }
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
        classpath 'com.google.firebase:perf-plugin:1.2.1'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'
    }
}

allprojects {
    repositories {
        mavenLocal()

        maven {
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven {
            url("${project(':react-native-background-fetch').projectDir}/libs")
        }
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

Here it is. I changed only compileSdkVersion and targetSdkVersion.

aboveyunhai commented 3 years ago

I just upgrade my build.gradle setting like yours, and did not see any build script problem except the permission.Activity_recognition on runtime, I believe this is due to the Google Policy changes and it can be solved by request permission manually by yourself. But this is on development setting instead of production. If you wonder the “Sample app” configuration, you can take a look, be ware that those configs can be wrong depends on your need. Sometimes the issue can be temporary cache issues from react native project.

wafa7abbes commented 3 years ago

Same issue here any solution so far ?

YahiaJabeur commented 3 years ago

I resolved the compiling issue by removing fitnessVersion = "18.0.0" But I m facing a crash when trying to get steps I'm using react-native 0.63 and react-native-google-fit 0.16.1

aboveyunhai commented 3 years ago

I resolved the compiling issue by removing fitnessVersion = "18.0.0" But I m facing a crash when trying to get steps I'm using react-native 0.63 and react-native-google-fit 0.16.1

It seems like you all have some own configurations. Notice that if you want to upgrade something please try to read through the commits. I remember the set fitness version is a "temporary" hot fix when googlefit decided to drop some deprecated codes🤔. And you shouldn't upgrade packages if it works fine since the version is fixed. Google fit will further drop some deprecated codes based on its recent updates.

The new functionalities introduced some new types that are not available from old fitness version. So your fitness version might want to match specific package version that you are using currently.

It's obvious that we can write some code to make version compatibility, but then the codebase will be a mess. Idk

ensargunesdogdu commented 3 years ago

This is because you should have fitness version 20.0.0 to run this library. I think this can be added to Documentation. Check out the release notes from here to find out what's changed. https://developers.google.com/android/guides/releases

aboveyunhai commented 3 years ago

@ensargunesdogdu good point, I can add it later. If developers does not hard set fitness version in their own apps, They wouldn't have the problem. Ppl who encountered the similar issues was because they followed the temp solution in the past when google decided to drop some deprecated codes, which it's fixed later but they did not remove the temp version.

Aurangempire commented 3 years ago

Same issue as --> https://github.com/StasDoskalenko/react-native-google-fit/issues/206#issuecomment-765308172

Getting below error: Cannot resolve symbol 'TYPE_SLEEP_SEGMENT'

But here: https://developers.google.com/fit/datatypes/sleep

Data type object | TYPE_SLEEP_SEGMENT

Mentioned in the DOC.

Any Solution?

gigby commented 2 years ago

@StasDoskalenko I faced with the same error but I didn't hardcode google fit version in by app/buildGradle file. Adding rootProject.ext.set("authVersion", "18.0.0") rootProject.ext.set("fitnessVersion", "20.0.0") helped me

ksetrin commented 2 years ago

Fixed by add

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29

        authVersion = "18.0.0"
        fitnessVersion = "20.0.0"
    }
    ...
}

to android/build.gradle