代码之家  ›  专栏  ›  技术社区  ›  Vishal G. Gohel

react native:任务:react native maps:CompileDebugRenderscript失败

  •  0
  • Vishal G. Gohel  · 技术社区  · 7 年前

    我正在尝试实现react native MapView 安卓系统。我确实跟着 github installation 指令,但尝试使用运行时遇到编译错误 react-native run-android 命令。

    任务:react native maps:compiledbugrenderscript失败

    失败:生成失败,出现异常。

    • 出了什么问题: 无法解析配置的所有文件:react native maps:debugcompilepasspath。 无法解析com.android。支持:支持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兼容: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:支持片段:28.0.0'-->'com.android.support:支持兼容: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地下室: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:支持注释”严格地说是“26.1.0”,因为 儿子:debugruntimeclasspath使用版本26.1.0 约束路径“MapViewDemo:react native maps:unspecified”->'com.android.support:support annotations“严格地说是”26.1.0“,原因如下 儿子:debugruntimeclasspath使用版本26.1.0
    • 试用 使用--stack trace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获得更多日志输出运行--扫描以获得完整的见解。

    • 获得更多帮助 https://help.gradle.org

    5秒内生成失败 8个可操作任务:8个已执行 错误无法在设备上安装应用程序,请阅读上面的错误以了解详细信息。 确保你有一个正在运行的Android模拟器或者一个连接的设备并且 设置Android开发环境: https://facebook.github.io/react-native/docs/getting-started.html 错误命令失败:gradlew.bat app:installdebug

    应用级渐变

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

    项目级梯度

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

    包.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"
    }
    }
    
    0 回复  |  直到 7 年前
        1
  •  1
  •   Vishal G. Gohel    7 年前

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

    要解决这个问题需要更新 反应本机映射 节点模块 编译DKversion 版本。

    项目名称>节点模块>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
  •   Ayesh Nipun    7 年前

    这对我也有效。

    修改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 到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

        3
  •  0
  •   Mr Lister hawi    7 年前

    你成功了吗?我找到了另一个解决办法。在我的例子中,这是因为react native(0.59.0)的版本因此,我在package.json文件格式中更改了react本机版本 0.59.0 ^0.58.6 是的。以及react native maps版本 ^0.23.0 是的。下面是其他步骤。

    1)在app level settings.gradle中,包含以下内容

    include ':react-native-maps'
    project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
    

    2)在项目级分级中,删除或评论

        ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 20
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    

    (在buildscript{}内)

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

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

    同时在maven{}(在所有项目{})中添加另一个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)现在更改应用程序级别梯度如下

    首先,将compilesdkversion更改为28并添加新的buildtoolversion

    compileSdkVersion 28
    buildToolsVersion "27.0.3"
    

    然后,更改min和target 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"/>
    

    (添加自己的API密钥 android:value )

    6)然后运行 npm install 试试这是否有效如果这不起作用,你必须从Android studio下载Android SDK在我的例子中,我下载了Android 7.0和6.0

        4
  •  0
  •   Desh Bourne    7 年前

    我使用这个npm安装“save”save“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编译,而maps使用26

        5
  •  0
  •   Deepak Kumrawat    6 年前

    两天后,我发现我的项目有问题。 我改变了 编译DKversion 我是说, 支持libversion 播放服务版本 在里面 android/build.gradle android/app/build.gradle 文件的值与中相同 node_modules/react-native-maps/lib/android/build.gradle node_modules/react-native-maps/build.gradle 档案,这对我有用。

    价值观 编译DKversion , 支持libversion 播放服务版本 在下面的所有文件中都是相同的。

    在里面 安卓/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+"
    }
    ...
    

    进入 安卓/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'
    }
    ...
    

    在里面 节点模块/react native maps/build.gradle 文件:

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