mauron85 / react-native-background-geolocation

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
Apache License 2.0
1.33k stars 561 forks source link

Fail to build after upgrade react-native and plugin on Android. #538

Closed DIGITALSQUAD closed 3 years ago

DIGITALSQUAD commented 3 years ago

Your Environment

Context

I've upgraded react-native from 0.59.8 to 0.63.3 and react-native-background-geolocation from 0.5.3 to 0.6.3. After that successfully works on iOS but fail to build on Android.

react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 2063 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...

> Configure project :@mauron85_react-native-background-geolocation
WARNING: The option setting 'android.bundle.enableUncompressedNativeLibs=false' is experimental and unsupported.
The current default is 'true'.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* Where:
Script '/Users/User/Projects/app_dir/ReactNative/MyApp/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 108

* What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':mauron85_react-native-background-geolocation' could not be found in project ':app'.

* 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 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

I've read issue #394 and modified settings.gradle and build.gradle and MainApplication.java as manual installation.

android/settings/gradle

rootProject.name = 'MyApp'
include ':@mauron85_react-native-background-geolocation-common'
project(':@mauron85_react-native-background-geolocation-common').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/common')
include ':@mauron85_react-native-background-geolocation'
project(':@mauron85_react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/lib')
include ':app'

andrid/app/buid.gradle

dependencies {
    implementation project(':@mauron85_react-native-background-geolocation')
}

MainApplication.java

    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new BackgroundGeolocationPackage(),
      ....

Expected Behavior

Success to build app.

Actual Behavior

Fail to build app

Possible Fix

Steps to Reproduce

  1. react-native run-android

Context

Debug logs

DIGITALSQUAD commented 3 years ago

Sorry, adding the line below solved the issue

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
zoolle commented 3 years ago

@DIGITALSQUAD I have the same issue but after all this implementation I still get the same error. its first time when I open an android app as I've worked only on ios. Can you please correct me if I am wrong?

MainApplication.java

private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new BackgroundGeolocationPackage()
            );
        }
      };

build.gradle

    dependencies {
        implementation project(':@mauron85_react-native-background-geolocation')
    }

settings.gradle

rootProject.name = 'MyProject'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':@mauron85_react-native-background-geolocation-common'
project(':@mauron85_react-native-background-geolocation-common').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/common')
include ':@mauron85_react-native-background-geolocation'
project(':@mauron85_react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/@mauron85/react-native-background-geolocation/android/lib')
include ':app'