【问题标题】:Could not find method implementation() for arguments React Native Maps找不到参数 React Native Maps 的方法 implementation()
【发布时间】:2018-08-29 01:19:39
【问题描述】:

当我 react-native run-android 我得到这个错误:

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

  • 在哪里: 构建文件 'C:\Users\xcrix\Desktop\projects\The Art Hunter\arthunterclient\android\build.gradle' 行:10

  • 出了什么问题: 评估根项目“arthunterclient”时出现问题。

    在 org.gradle.api.internal.artifacts.dsl.dependencies 类型的对象上找不到参数 [project ':react-native-maps', build_5yzom2lyrek7xvyvgp2oo4gzp$_run_closure1$_closure3$_closure4@1d634cfe] 的方法 implementation() .DefaultDependencyHandler。

Android/build.gradle:

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

buildscript {
    repositories {
        jcenter()
         google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'  
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:10.0.1'
   implementation 'com.google.android.gms:play-services-maps:10.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

    }
}

Android/gradle.properties

android.enableAapt2=false
android.useDeprecatedNdk=true

Android/settings.gradle

rootProject.name = 'arthunterclient'

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

Android/app/build.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"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.arthunterclient"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    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]
            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 fileTree(dir: "libs", include: ["*.jar"])
  implementation "com.android.support:appcompat-v7:23.0.1"
  implementation "com.facebook.react:react-native:+"
  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:10.0.1'
  implementation 'com.google.android.gms:play-services-maps:10.0.1'
}

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

Android/gradle/wrapper/gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

我花了 5 个多小时来解决这个问题。在互联网上尝试了所有方法,但还是一样...

【问题讨论】:

  • 嗨。我知道 3 个月后回复可能会迟到,但对于其他将访问此问题的人来说,this 解决方案对我有用。

标签: android react-native gradle react-native-maps


【解决方案1】:

这个:

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:10.0.1'
implementation 'com.google.android.gms:play-services-maps:10.0.1'

android/build.gradle 中删除它。仅保留在android/app/build.gradle

【讨论】:

    猜你喜欢
    • 2020-04-16
    • 2018-05-24
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 2021-01-08
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多