英文:
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版本在:
- android/gradle/gradle-wrapper-properties 文件中更改Gradle版本
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip - 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:
- android/gradle/gradle-wrapper-properties file change the gradle version
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip - 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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论