Could not find method namespace() for arguments [com.android.mylib] on extension 'android' of type com.android.build.gradle.LibraryExtension

huangapple go评论102阅读模式
英文:

Could not find method namespace() for arguments [com.android.mylib] on extension 'android' of type com.android.build.gradle.LibraryExtension

问题

我正在尝试按照官方文档在Android Studio中创建一个库。但在这个特定的项目中,我遇到了这个问题。如果我创建一个新项目并创建新库,我就不会遇到任何问题。这意味着只有这个项目存在问题。

我的库 Gradle

plugins {
    id 'com.android.library'
}

android {
    namespace 'com.android.mylib'
    compileSdkVersion 33

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 33

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

App Gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 33
    buildToolsVersion "30.0.2"
    testBuildType "beta"

    defaultConfig {
        applicationId "com.app.etc"
        minSdkVersion 23
        targetSdkVersion 33
        versionCode 327
    }
}

我已经搜索了一些问题,但根据那些答案,一切似乎都是正确的。我已经清除了缓存并重新启动了Android Studio。

以下是错误信息。

在评估项目':mylibrary'时出现问题。

Caused by: 
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: 在类型com.android.build.gradle.LibraryExtension的extension 'android'上找不到方法namespace()的参数[com.example.mylibrary]。
英文:

I am trying to create a library in android studio by following this official documentation. But in this particular project, I am facing this issue. if I create new project and create new lib I don't face any issue. It means something is wrong with this project only.

My Lib Gradle

> plugins {
id 'com.android.library'
}

android {
    namespace 'com.android.mylib'
    compileSdkVersion 33

defaultConfig {
    minSdkVersion 26
    targetSdkVersion 33

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

App Gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 33
    buildToolsVersion "30.0.2"
    testBuildType "beta"

    defaultConfig {
        applicationId "com.app.etc"
        minSdkVersion 23
        targetSdkVersion 33
        versionCode 327

> I have searched some questions, but according to those answers, everything seems correct. i have invalidated cache and restarted the android studio as well.
>
> Here is the error.

 A problem occurred evaluating project ':mylibrary'

Caused by: 

org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method namespace() for arguments [com.example.mylibrary] on extension 'android' of type com.android.build.gradle.LibraryExtension.

答案1

得分: 5

这是应用中使用的Gradle版本的问题,一些插件需要最新版本的Gradle。

尝试更改Gradle版本在:

  1. android/gradle/gradle-wrapper-properties 文件中更改Gradle版本
    distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
  2. android/build.gradle 文件
    在依赖项下更改以下行以使用最新的Gradle版本
    classpath 'com.android.tools.build:gradle:7.5.2'
英文:

That is the problem with the Gradle version used in the app some plugins want latest version of the Gradle

Try to change the Gradle version in:

  1. android/gradle/gradle-wrapper-properties file change the gradle version
    distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
  2. android/build.gradle file
    Under dependencies change the following line to use the latest gradle version
    classpath 'com.android.tools.build:gradle:7.5.2'

huangapple
  • 本文由 发表于 2023年2月18日 20:10:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定