React Native:任务:react-native-maps:compileDebugRenderscript失败

时间:2019-03-14 06:27:43

标签: react-native react-native-maps

我正在尝试为Android实现React Native MapView。我确实遵循了github installation的说明,但是当我尝试使用react-native run-android命令运行时遇到编译错误。

  
    

任务:react-native-maps:compileDebugRenderscript失败

  
     

失败:构建失败,并出现异常。

     
      
  • 出了什么问题:   无法解析配置':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”   儿子:debugRuntimeClasspath使用版本26.1.0       约束路径'MapViewDemo:react-native-maps:unspecified'->'com.android.support:support-annotations'严格为'26 .1.0',原因如下   儿子:debugRuntimeClasspath使用版本26.1.0
  •   
  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。

  • https://help.gradle.org

  • 获得更多帮助

5秒内失败 8个可执行任务:已执行8个 错误无法在设备上安装该应用程序,有关详细信息,请阅读上述错误。 确保您正在运行Android模拟器或已连接设备,并且 设置您的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"
}
}

5 个答案:

答案 0 :(得分:0)

这对我也有用。

按如下所示修改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():

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添加到a​​ndroid / 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

答案 1 :(得分:0)

经过两天的苦苦挣扎,我自己找到了解决方案。真正的问题是我的项目使用compileSdkVersion = 28react-native-maps node_module并使用了不同版本的compileSdkVersion

要解决此问题,需要更新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版本和支持库版本相同。

答案 2 :(得分:0)

您能够使它正常工作吗?我找到了另一个解决方案。就我而言,这是由于react-native(0.59.0)的版本引起的。所以我将我的package.json文件形式的react-native版本从0.59.0更改为^0.58.6。以及react-native-maps版本为^0.23.0。这是其他步骤。

1)在应用级别设置中。渐变,请添加

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"
}

(在buildscript {}内部)

3)也在项目级别gradle中, 更改类路径。 build.gradle版本到3.1.1

classpath 'com.android.tools.build:gradle:3.1.1'

还要在maven {}中(在allprojects {}内部)添加另一个URL

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"

然后,如下更改min和目标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

答案 3 :(得分:0)

我使用此npm安装解决了这个问题。保存“ react-native-maps @ jerolimov / react-native-maps#fix-rn59rc-compile-issues”

来自:https://github.com/react-native-community/react-native-maps/pull/2702

问题是React native 0.59+可以使用compileSdkVersion 28进行编译,而地图使用26

答案 4 :(得分:0)

2天后,我在项目中发现了问题。 我更改了 compileSdkVersion supportLibVersion playServicesVersion 中的值   将android/build.gradleandroid/app/build.gradle文件设置为与node_modules/react-native-maps/lib/android/build.gradlenode_modules/react-native-maps/build.gradle文件中相同的值,这对我有用。

compileSdkVersion supportLibVersion playServicesVersion 的值在以下所有文件中均相同。

  

android / build.gradle 文件中:

...
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+"
}
...
  

android / app / build.gradle 文件中:

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

node_modules / react-native-maps / lib / android / build.gradle 文件中:

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

node_modules / react-native-maps / build.gradle 文件中:

...
ext {
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 28
    supportLibVersion = '28.0.0'
    playServicesVersion = '16.1.0'
  }
...