React Native:任务:react-native-maps:compileDebugRenderscript FAILED
React Native : Task :react-native-maps:compileDebugRenderscript FAILED
我正在尝试为 Android 实施 React Native MapView
。我确实遵循了 github installation 说明,但是当我尝试使用 react-native run-android
命令 运行 时遇到编译错误。
Task :react-native-maps:compileDebugRenderscript FAILED
失败:构建失败,出现异常。
- 出了什么问题:
无法解析配置“:react-native-maps:debugCompileClasspath”的所有文件。
无法解析 com.android.support:support-compat:26.1.0。
要求:
项目:react-native-maps
找不到满足版本限制的 'com.android.support:support-compat' 版本:
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' -
-> 'com.android.support:support-compat:28.0.0'
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' -
-> 'com.android.support:support-core-utils:28.0.0' --> 'com.android.support:support-compat:28.0.0'
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' -
-> 'com.android.support:support-fragment:28.0.0' --> 'com.android.support:support-compat:28.0.0'
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' -
-> 'com.android.support:support-vector-drawable:28.0.0' --> 'com.android.support:support-compat:28.0.0'
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.google.android.gms:play-services-base:16.0.1' --> 'com.google.android.gms:play-serv
ices-basement:16.0.1' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-compat:26.1.0'
依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' -
-> 'com.android.support:support-core-utils:28.0.0' --> 'com.android.support:loader:28.0.0' --> 'com.android.support:support-compat:28.0.0'
'com.android.support:support-annotations' 严格 '26.1.0' 因为以下原因
儿子:debug运行timeClasspath 使用版本 26.1.0
约束路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' 因为以下原因
儿子:debug运行timeClasspath 使用版本 26.1.0
尝试:
运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
获取更多帮助
5 秒内构建失败
8 个可操作任务:8 个已执行
错误无法在设备上安装应用程序,请阅读上面的错误以了解详细信息。
确保你有一个 Android 模拟器 运行ning 或连接的设备并且有
设置您的 Android 开发环境:
https://facebook.github.io/react-native/docs/getting-started.html
错误 命令失败:gradlew.bat app:installDebug
应用级别gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.mapviewdemo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86-64"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// 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:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
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-maps')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
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:16.1.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
}
// 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'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:28.0.0'
force 'com.android.support:appcompat-v7:28.0.0'
}
}
项目级别gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
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"
}
}
}
Package.json
{
"name": "MapViewDemo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.8.3",
"react-native": "0.59.0",
"react-native-maps": "^0.23.0"
},
"devDependencies": {
"@babel/core": "7.3.4",
"@babel/runtime": "7.3.4",
"babel-jest": "24.5.0",
"jest": "24.5.0",
"metro-react-native-babel-preset": "0.53.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
这对我也有用。
修改android/build.gradle如下
1) 在存储库中添加 google()
buildscript {
repositories {
jcenter()
// add google() here
google()
2) 将 com.android.tools.build.gradle 更新为 3.1.0
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.2.3'
// update from 2.2.3 to 3.1.0
classpath 'com.android.tools.build:gradle:3.1.0'
3) 添加 google() inside repositories after dependencies :
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
allprojects {
repositories {
mavenLocal()
jcenter()
// add googgle() here
google()
4) 添加 android.enableAapt2=false
到 android/gradle.properties
android.enableAapt2=false // < --- add here
android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
5) 更新 android/gradle/wrapper/gradle-wrapper.properties 中的 gradle 版本:
// from version 2.14.1
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
// change to 4.10.1
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
6) 运行 react-native run-android
经过两天的努力,我通过 self.The 找到了解决方案,真正的问题是我的项目使用 compileSdkVersion = 28
和 react-native-maps
node_module 使用不同版本的 [=13] =].
要解决此问题需要更新 react-native-maps
node_module compileSdkVersion
版本。
project_name>node_modules>react-native-maps>lib>android>build.gradle
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
模块编译SDK版本和支持库版本与工程编译SDK版本和支持库版本一致
你能做到吗?我找到了另一个解决方案。在我的例子中,发生这种情况是因为 react-native (0.59.0) 的版本。所以我将 package.json 文件格式 0.59.0
中的 react-native 版本更改为 ^0.58.6
。和 react-native-maps 版本到 ^0.23.0
。这是其他步骤。
1) 在应用程序级别 settings.gradle,包括此
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
2) 在项目级别 gradle,删除或评论
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
(在构建脚本{}内)
3) 也在项目级别 gradle,
更改类路径。 build.gradle 版本到 3.1.1
classpath 'com.android.tools.build:gradle:3.1.1'
还在 maven{} 中添加另一个 url(在 allprojects{} 中)
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "https://maven.google.com"
url "$rootDir/../node_modules/react-native/android"
}
4) 现在更改应用级别 gradle 如下
首先,将compileSdkVersion改为28并添加新的buildToolVersion
compileSdkVersion 28
buildToolsVersion "27.0.3"
然后,如下更改最小值和目标 SdkVersion(在 defaultConfig 内)
defaultConfig {
applicationId "com.mapviewdemo"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
5) 在你的 AndroidManifest.xml,
首先添加这段代码。这是为了授予访问您设备上的位置的权限。在 <aplication>
标签之前添加这个。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
那么你必须在 </application>
标签之前添加你的元数据。
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBTSDBtI7_dfdfBeYkNAtdQ8sT67HiOuO0VU"/>
(为 android:value
添加您自己的 API 密钥)
6) 然后 运行 npm install
并尝试这是否有效。如果这不起作用,您必须从 android studio 下载 Android SDK。就我而言,我下载了 Android 7.0 和 6.0
我使用这个 npm install 解决了这个问题 保存“react-native-maps@jerolimov/react-native-maps#fix-rn59rc-compile-issues”
来自:https://github.com/react-native-community/react-native-maps/pull/2702
问题出在使用 compileSdkVersion 28 编译并且映射使用 26 的 React native 0.59+
2 天后我在我的项目中发现了问题。
我更改了 compileSdkVersion、supportLibVersion 和 playServicesVersion 的值
android/build.gradle
和 android/app/build.gradle
文件的值与 node_modules/react-native-maps/lib/android/build.gradle
和 node_modules/react-native-maps/build.gradle
文件中的值相同,这对我有用。
compileSdkVersion、supportLibVersion和playServicesVersion的值在以下所有文件中都是相同的。
in android/build.gradle file:
...
ext {
compileSdkVersion = 28
targetSdkVersion = 27
buildToolsVersion = "28.0.3"
minSdkVersion = 16
supportLibVersion = "28.0.0"
playServicesVersion = "16.1.0" // or set latest version
androidMapsUtilsVersion = "0.5+"
}
...
in android/app/build.gradle file:
...
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.reactnativeapp2"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
...
...
}
...
dependencies {
...
...
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
}
...
in node_modules/react-native-maps/lib/android/build.gradle file:
...
android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
}
}
dependencies {
...
implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation 'com.google.maps.android:android-maps-utils:0.5'
}
...
in node_modules/react-native-maps/build.gradle file:
...
ext {
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = '28.0.0'
playServicesVersion = '16.1.0'
}
...
我正在尝试为 Android 实施 React Native MapView
。我确实遵循了 github installation 说明,但是当我尝试使用 react-native run-android
命令 运行 时遇到编译错误。
Task :react-native-maps:compileDebugRenderscript FAILED
失败:构建失败,出现异常。
- 出了什么问题: 无法解析配置“:react-native-maps:debugCompileClasspath”的所有文件。 无法解析 com.android.support:support-compat:26.1.0。 要求: 项目:react-native-maps 找不到满足版本限制的 'com.android.support:support-compat' 版本: 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' - -> 'com.android.support:support-compat:28.0.0' 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' - -> 'com.android.support:support-core-utils:28.0.0' --> 'com.android.support:support-compat:28.0.0' 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' - -> 'com.android.support:support-fragment:28.0.0' --> 'com.android.support:support-compat:28.0.0' 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' - -> 'com.android.support:support-vector-drawable:28.0.0' --> 'com.android.support:support-compat:28.0.0' 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.google.android.gms:play-services-base:16.0.1' --> 'com.google.android.gms:play-serv ices-basement:16.0.1' --> 'com.android.support:support-v4:26.1.0' --> 'com.android.support:support-compat:26.1.0' 依赖路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.facebook.react:react-native:0.59.0' --> 'com.android.support:appcompat-v7:28.0.0' - -> 'com.android.support:support-core-utils:28.0.0' --> 'com.android.support:loader:28.0.0' --> 'com.android.support:support-compat:28.0.0' 'com.android.support:support-annotations' 严格 '26.1.0' 因为以下原因 儿子:debug运行timeClasspath 使用版本 26.1.0 约束路径 'MapViewDemo:react-native-maps:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' 因为以下原因 儿子:debug运行timeClasspath 使用版本 26.1.0
尝试: 运行 使用 --stacktrace 选项获取堆栈跟踪。 运行 使用 --info 或 --debug 选项以获得更多日志输出。 运行 使用 --scan 以获得完整的见解。
- 获取更多帮助
5 秒内构建失败 8 个可操作任务:8 个已执行 错误无法在设备上安装应用程序,请阅读上面的错误以了解详细信息。 确保你有一个 Android 模拟器 运行ning 或连接的设备并且有 设置您的 Android 开发环境: https://facebook.github.io/react-native/docs/getting-started.html 错误 命令失败:gradlew.bat app:installDebug
应用级别gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.mapviewdemo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86-64"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// 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:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
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-maps')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
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:16.1.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
}
// 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'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:28.0.0'
force 'com.android.support:appcompat-v7:28.0.0'
}
}
项目级别gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
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"
}
}
}
Package.json
{
"name": "MapViewDemo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.8.3",
"react-native": "0.59.0",
"react-native-maps": "^0.23.0"
},
"devDependencies": {
"@babel/core": "7.3.4",
"@babel/runtime": "7.3.4",
"babel-jest": "24.5.0",
"jest": "24.5.0",
"metro-react-native-babel-preset": "0.53.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
这对我也有用。
修改android/build.gradle如下
1) 在存储库中添加 google()
buildscript {
repositories {
jcenter()
// add google() here
google()
2) 将 com.android.tools.build.gradle 更新为 3.1.0
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.2.3'
// update from 2.2.3 to 3.1.0
classpath 'com.android.tools.build:gradle:3.1.0'
3) 添加 google() inside repositories after dependencies :
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
allprojects {
repositories {
mavenLocal()
jcenter()
// add googgle() here
google()
4) 添加 android.enableAapt2=false
到 android/gradle.properties
android.enableAapt2=false // < --- add here
android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
5) 更新 android/gradle/wrapper/gradle-wrapper.properties 中的 gradle 版本:
// from version 2.14.1
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
// change to 4.10.1
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
6) 运行 react-native run-android
经过两天的努力,我通过 self.The 找到了解决方案,真正的问题是我的项目使用 compileSdkVersion = 28
和 react-native-maps
node_module 使用不同版本的 [=13] =].
要解决此问题需要更新 react-native-maps
node_module compileSdkVersion
版本。
project_name>node_modules>react-native-maps>lib>android>build.gradle
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
模块编译SDK版本和支持库版本与工程编译SDK版本和支持库版本一致
你能做到吗?我找到了另一个解决方案。在我的例子中,发生这种情况是因为 react-native (0.59.0) 的版本。所以我将 package.json 文件格式 0.59.0
中的 react-native 版本更改为 ^0.58.6
。和 react-native-maps 版本到 ^0.23.0
。这是其他步骤。
1) 在应用程序级别 settings.gradle,包括此
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
2) 在项目级别 gradle,删除或评论
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 20
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
(在构建脚本{}内)
3) 也在项目级别 gradle, 更改类路径。 build.gradle 版本到 3.1.1
classpath 'com.android.tools.build:gradle:3.1.1'
还在 maven{} 中添加另一个 url(在 allprojects{} 中)
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "https://maven.google.com"
url "$rootDir/../node_modules/react-native/android"
}
4) 现在更改应用级别 gradle 如下
首先,将compileSdkVersion改为28并添加新的buildToolVersion
compileSdkVersion 28
buildToolsVersion "27.0.3"
然后,如下更改最小值和目标 SdkVersion(在 defaultConfig 内)
defaultConfig {
applicationId "com.mapviewdemo"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
5) 在你的 AndroidManifest.xml,
首先添加这段代码。这是为了授予访问您设备上的位置的权限。在 <aplication>
标签之前添加这个。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
那么你必须在 </application>
标签之前添加你的元数据。
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBTSDBtI7_dfdfBeYkNAtdQ8sT67HiOuO0VU"/>
(为 android:value
添加您自己的 API 密钥)
6) 然后 运行 npm install
并尝试这是否有效。如果这不起作用,您必须从 android studio 下载 Android SDK。就我而言,我下载了 Android 7.0 和 6.0
我使用这个 npm install 解决了这个问题 保存“react-native-maps@jerolimov/react-native-maps#fix-rn59rc-compile-issues”
来自:https://github.com/react-native-community/react-native-maps/pull/2702
问题出在使用 compileSdkVersion 28 编译并且映射使用 26 的 React native 0.59+
2 天后我在我的项目中发现了问题。
我更改了 compileSdkVersion、supportLibVersion 和 playServicesVersion 的值
android/build.gradle
和 android/app/build.gradle
文件的值与 node_modules/react-native-maps/lib/android/build.gradle
和 node_modules/react-native-maps/build.gradle
文件中的值相同,这对我有用。
compileSdkVersion、supportLibVersion和playServicesVersion的值在以下所有文件中都是相同的。
in android/build.gradle file:
...
ext {
compileSdkVersion = 28
targetSdkVersion = 27
buildToolsVersion = "28.0.3"
minSdkVersion = 16
supportLibVersion = "28.0.0"
playServicesVersion = "16.1.0" // or set latest version
androidMapsUtilsVersion = "0.5+"
}
...
in android/app/build.gradle file:
...
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.reactnativeapp2"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
...
...
}
...
dependencies {
...
...
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
}
...
in node_modules/react-native-maps/lib/android/build.gradle file:
...
android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
}
}
dependencies {
...
implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation 'com.google.maps.android:android-maps-utils:0.5'
}
...
in node_modules/react-native-maps/build.gradle file:
...
ext {
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = '28.0.0'
playServicesVersion = '16.1.0'
}
...