React-native-gesture-handler: タイプorg.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandlerのオブジェクトで引数[com.facebook.react:react-native:+]のメソッドcompileOnly()が見つかりませんでした。

作成日 2018年11月30日  ·  3コメント  ·  ソース: software-mansion/react-native-gesture-handler

公式文書に従ってreact-navigation3.0.2を使用するように構成します
私のpackage.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"
  }
}

および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
}

次にreact-nativerun-android
エラーを見つける

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.

それを解決する方法を知りたいです。

最も参考になるコメント

ビルドファイル '/Users/mao/Desktop/lzbk/mpx/node_modules/react-native-gesture-handler/android/build.gradle'で、依存関係セクションの「compileOnly」を「compile」に変更します。 私はReactNativeを初めて使用するので、理由はわかりませんが、node_modules内の他のパッケージを調べたところ、それらが「コンパイル」を使用していることがわかりました。 幸運を。

全てのコメント3件

ビルドファイル '/Users/mao/Desktop/lzbk/mpx/node_modules/react-native-gesture-handler/android/build.gradle'で、依存関係セクションの「compileOnly」を「compile」に変更します。 私はReactNativeを初めて使用するので、理由はわかりませんが、node_modules内の他のパッケージを調べたところ、それらが「コンパイル」を使用していることがわかりました。 幸運を。

私は以下の変更によってこの問題を解決しました:

  1. android/build/gradle構成を変更します。 これは私のコードの一部です:
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()
    }
}

google()buildscriptallprojectsに追加し、クラスパスのgradleバージョンを変更します。 ...\node_modules\react-native-vector-icons\android\build.gradle開くと、クラスパスのgradleバージョンが3.1.4であることがわかります。そのため、この変更を行う必要があります。

  1. Androidプロジェクトで、 android/gradle/wrapper/gradle-wrapper.properties開き、distributionUrlを変更します。
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

このライブラリは3.1.4以降のgradleバージョンに依存しているため、それよりも新しいバージョンを設定する必要があります。

プロジェクトを再構築すると、最終的に機能します。

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

このようにmakebuild.gradleファイルで解決しました。

このページは役に立ちましたか?
0 / 5 - 0 評価