React-native-gesture-handler: Die Methode compilierenOnly() für die Argumente [com.facebook.react:react-native:+] für ein Objekt vom Typ org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler konnte nicht gefunden werden.

Erstellt am 30. Nov. 2018  ·  3Kommentare  ·  Quelle: software-mansion/react-native-gesture-handler

Ich konfiguriere es gemäß offiziellen Dokumenten, um React-Navigation3.0.2 zu verwenden
mein Paket.json

{
  "name": "mpx",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "0.55.4",
    "react-native-gesture-handler": "^1.0.10",
    "react-native-scrollable-tab-view": "^0.10.0",
    "react-native-vector-icons": "^6.1.0",
    "react-navigation": "^3.0.2",
    "teaset": "^0.5.10"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "babel-preset-react-native": "4.0.1",
    "jest": "23.6.0",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

und MainActivity.java

package com.mpx;

import com.facebook.react.ReactActivity;
// add start (react-native-gesture-handler)
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
// add end
public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    <strong i="10">@Override</strong>
    protected String getMainComponentName() {
        return "mpx";
    }
    // add start (react-native-gesture-handler)
    <strong i="11">@Override</strong>
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, getMainComponentName()) {
            <strong i="12">@Override</strong>
            protected ReactRootView createRootView() {
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
            }
        };
    }
    // add end
}

dann reaktiv-native run-android
Fehler finden

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/mao/Desktop/lzbk/mpx/node_modules/react-native-gesture-handler/android/build.gradle' line: 32

* What went wrong:
A problem occurred evaluating project ':react-native-gesture-handler'.
> 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.

Ich möchte wissen, wie man es löst.

Hilfreichster Kommentar

Ändern Sie in der Build-Datei ‚/Users/mao/Desktop/lzbk/mpx/node_modules/react-native-gesture-handler/android/build.gradle‘ im Abschnitt Abhängigkeiten „compileOnly“ in „compile“. Ich bin neu bei React Native, also weiß ich nicht warum, aber ich habe mir gerade andere Pakete in node_modules angesehen und festgestellt, dass sie "compile" verwenden. Viel Glück.

Alle 3 Kommentare

Ändern Sie in der Build-Datei ‚/Users/mao/Desktop/lzbk/mpx/node_modules/react-native-gesture-handler/android/build.gradle‘ im Abschnitt Abhängigkeiten „compileOnly“ in „compile“. Ich bin neu bei React Native, also weiß ich nicht warum, aber ich habe mir gerade andere Pakete in node_modules angesehen und festgestellt, dass sie "compile" verwenden. Viel Glück.

Ich habe dieses Problem durch folgende Änderungen gelöst:

  1. Ändern Sie die Konfiguration in android/build/gradle . Dies ist ein Teil meines Codes:
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

fügen Sie google() zu buildscript und allprojects und ändern Sie die Gradle-Version im Klassenpfad. Öffnen Sie ...\node_modules\react-native-vector-icons\android\build.gradle , Sie werden feststellen, dass die Gradle-Version im Klassenpfad 3.1.4 ist, deshalb müssen wir diese Änderung vornehmen.

  1. Öffnen Sie in Ihrem Android-Projekt android/gradle/wrapper/gradle-wrapper.properties , ändern Sie die DistributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

Da diese Bibliothek von einer Gradle-Version über 3.1.4 abhängt, sollten wir eine neue Version als diese festlegen.

Bauen Sie das Projekt neu auf, es funktioniert endlich.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com" }
    }
}

gelöst durch make build.gradle-Datei wie diese.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

brunolemos picture brunolemos  ·  3Kommentare

rt2zz picture rt2zz  ·  4Kommentare

TerrerSandman picture TerrerSandman  ·  3Kommentare

rgangopadhya picture rgangopadhya  ·  4Kommentare

brentvatne picture brentvatne  ·  5Kommentare