首页 > 解决方案 > Android Studio 错误找不到模块项目参数的方法 android()

问题描述

尝试将 SendBird 消息添加到 Android 中的现有应用程序。

我将 SendBird ( https://github.com/smilefam/SendBird-Android ) 作为模块导入到 Android Studio 中的工作 Android 应用程序项目中。

获取此构建同步错误:

在 org.gradle.api.Project 类型的项目“:SendBird”上找不到参数 [build_cmuu8gl1t8ajvfzi59kru30vs$_run_closure1@20899a01] 的方法 android()。

此错误指向 SendBird build.gradle 文件作为问题。我在下面包含了项目和模块的 build.gradle 文件。

项目:VitalConcern8 build.gradle

    buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.2.0'

        classpath project(':SendBird')

        classpath project(':app')


    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块:app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.church.george.vitalconcern"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 2
        versionName "1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'org.apache.commons:commons-text:1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.volley:volley:1.1.0'

}

模块:SendBird build.gradle

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.sendbird.android.sample"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode getVersionCode()
        versionName getVersionName()
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }

}


repositories {
    maven { url "https://raw.githubusercontent.com/smilefam/SendBird-SDK-Android/master/" }
    google()
}

dependencies {


    implementation fileTree(include: ['*.jar'], dir: 'libs')



    // Required for local unit tests (JUnit 4 framework)
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    // SendBird
    implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.88'

    // Android support libraries
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    // Firebase
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

    // External libraries
    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'org.jsoup:jsoup:1.11.2'
    implementation 'com.dinuscxj:circleprogressbar:1.1.1'
    implementation 'com.github.stfalcon:multiimageview:0.1'
}
apply plugin: 'com.google.gms.google-services'

apply plugin: 'com.android.library'
apply plugin: 'com.android.application'

标签: androidgradle

解决方案


这是因为您的SendBirdbuild.gradle 中有以下代码:

apply plugin: 'com.android.library'
apply plugin: 'com.android.application'

您只需要以下内容:

apply plugin: 'com.android.library'

不要忘记将它作为 SendBird build.gradle 的第一行移动。您还需要从中删除它:

    applicationId "com.sendbird.android.sample"

因为你不能有一个库模块的 applicationId 。


推荐阅读