评估项目':app'时发生问题。可能是build.gradle问题

时间:2019-07-31 15:43:36

标签: react-native gradle

我不断收到此错误:

  

配置项目':app'时发生问题。

每当我对本机运行Android做出反应时。我的怀疑是我在两个build.gradle(s)之一中搞砸了

错误日志:(cmd)

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where: Build file 'D:\Programs\reactnative\tokobangun\android\app\build.gradle' line:
103

* What went wrong: A problem occurred evaluating project ':app'.
Could not find method android() for arguments [build_52alt8ebvpuajag0a3orrbaix$_run_closure1@36f24a11] on project
':app' of type org.gradle.api.Project.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong: A problem occurred configuring project ':app'.
Failed to notify project evaluation listener.
Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.
Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.

我尝试过:

  1. react-native run-android

  2. 逐渐清洁

两者都给我相同的结果。

android / app / build.gradle

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
    }
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

/** . . . */

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.tokobangun"
        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-onesignal')
    implementation project(':react-native-webview')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
}

// 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 / build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.0")

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

我确实认为我在某个地方搞砸了android / build.gradle,我试图将其恢复到没有错误但无济于事的状态。有什么想法吗?

哦,如果您发现我的问题格式不够,请告诉我,我会尽可能地对其进行调整。预先感谢。

1 个答案:

答案 0 :(得分:0)

在android / build.gradle中,将classpath(“ com.android.tools.build:gradle:3.4.0”)更改为classpath'com.android.tools.build:gradle:3.3.0',然后重试< / p>