0

Estou tentando implementar a biblioteca React-native-maps no meu projeto, quando executo react-native run-android recebo este erro no CMD:

* Where:
Build file 'C:\Users\Henrique\Documents\New folder\NoExpo\AwesomeProject\node_modules\react-native-maps\lib\android\build.gradle' line: 46

* What went wrong:
A problem occurred evaluating project ':react-native-maps'.
> Could not find method compileOnly() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.449 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Configurei o arquivo build.gradle assim:

dependencies {
    compile project(':react-native-maps')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}
3
  • Qual a versão do Gradle ?
    – NoobSaibot
    6/05/2018 às 21:45
  • classpath 'com.android.tools.build:gradle:2.2.3' 6/05/2018 às 21:47
  • Altere para classpath 'com.android.tools.build:gradle:3.0.1' e veja se funciona.
    – NoobSaibot
    6/05/2018 às 21:48

2 Respostas 2

1

Se você não tiver propriedades definidas para todo o projeto definidas e tiver uma versão de serviços de reprodução diferente daquela incluída nessa biblioteca, use o seguinte (alternar 10.0.1 para a versão desejada):

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

Em seu android/settings.gradle:

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

0

Complementando, o post acima, se você realizou os reparos e continua dando problema, você pode limpar o build utilizando os seguintes comandos.

Limpar android

rm -rf android/app/build && rm -rf android/build && rm -rf android/.gradle && rm -rf android/build.gradle-e

Limpar IOS

rm -rf ios/build && rm -rf ios/Pods && rm -rf ios/Podfile.lock

Pode até criar um script no seu package para agilizar esse processo.

"clean": "yarn clean:android && yarn clean:ios && rm -rf node_modules && rm -f yarn.lock",
"clean:android": "rm -rf android/app/build && rm -rf android/build && rm -rf android/.gradle && rm -rf android/build.gradle-e",
"clean:ios": "rm -rf ios/build && rm -rf ios/Pods && rm -rf ios/Podfile.lock",
"build": "yarn && yarn build:android && yarn build:ios",
"build:android": "npx jetifier",
"build:ios": "cd ios/ && pod install",

Isto automatizaria o build.

Boa sorte!

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .