首页 > 解决方案 > react-native-geolocation-service 构建问题

问题描述

问题:

我有一个 react native 应用程序,我正在使用 react-native-geolocation-service。在 npm install 之后,我尝试使用那里的 android studio 构建项目它失败并导致我出现这样的错误。

错误:找不到符号变量 ActivityCompat

这是我的构建 Gradle 文件。

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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.2")

        // 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' }
    }
}

我尝试了很多在 Internet 上找到解决此问题的方法,但我无法做到。那么有人可以帮我解决这个问题吗?谢谢

标签: androidreact-native

解决方案


react native 0.60+ 已迁移到 Android X 所以你需要在添加新库时将文件转换为 AndroidX 使用 jetifier

npm install --save-dev jetifier
npx jetify (may take a while)
npx react-native run-android 

推荐阅读