Gradle Core Plugins (plugin is not in 'org.gradle' namespace)

默認在Android Studio Bumblebee 基于Gradle7.1創(chuàng)建項目引入Android Gradle plugin插件會報

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)

因為Gradle7.1項目以后默認gradle是這樣設(shè)置的

  • 項目builder.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '4.2.2' apply false
    id 'com.android.library' version '4.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • 項目setting.gradle
pluginManagement {
    repositories {
        maven(){
            url=uri('repo')
        }
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(org.gradle.api.initialization.resolve.RepositoriesMode.PREFER_PROJECT)
    repositories {
        maven{
            url uri('repo')
        }
        google()
        mavenCentral()
    }
}

rootProject.name = "Test"
include ':app'

如果之前的文章引用本地插件是這樣:

  • build.gradle
buildscript {
    repositories {
        google()
        jcenter()
        maven{
            url uri('repo')
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
       //引入插件名
        classpath "com.javassist:modify:1.0.1"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • settings.gradle
include ':app', ':javassist'
rootProject.name='Test'
  • app moudle的build.gradle
apply plugin: 'com.android.application'
//插件
apply plugin: 'com.javassist'
android {
    compileSdkVersion 30
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.mysiga.ma"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

在官方文檔已經(jīng)說改動了

image.png

開始嘗試在項目build.gradle添加

plugins {
    id 'com.android.application' version '4.2.2' apply false
    id 'com.android.library' version '4.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
//插件
    id 'com.javassist' version '1.0.0' apply false
}

還是包同樣的錯誤沒有找到插件,google搜索了下有這些回答:

  • 代理問題
  • 各種嘗試問題
    都沒有解決問題丧荐,最終發(fā)現(xiàn)對比少buildscript最后只有把buildscript放到項目build.gradle最頂部惋戏,如:
    buildscript {
        dependencies {
            classpath "com.javassist:CustomPlugin:1.0.0"
        }
    }
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '4.2.2' apply false
    id 'com.android.library' version '4.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}

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

且在 app moudle的build.gradle加:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
//引入插件
    id 'com.mysiga.javassist'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.mysiga.ma"
        minSdk 26
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

才編譯通過。

擴展閱讀

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市澡为,隨后出現(xiàn)的幾起案子天揖,更是在濱河造成了極大的恐慌,老刑警劉巖诸典,帶你破解...
    沈念sama閱讀 222,378評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件描函,死亡現(xiàn)場離奇詭異,居然都是意外死亡狐粱,警方通過查閱死者的電腦和手機舀寓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來肌蜻,“玉大人互墓,你說我怎么就攤上這事〗眩” “怎么了篡撵?”我有些...
    開封第一講書人閱讀 168,983評論 0 362
  • 文/不壞的土叔 我叫張陵判莉,是天一觀的道長。 經(jīng)常有香客問我育谬,道長券盅,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,938評論 1 299
  • 正文 為了忘掉前任膛檀,我火速辦了婚禮锰镀,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘宿刮。我一直安慰自己互站,他們只是感情好,可當我...
    茶點故事閱讀 68,955評論 6 398
  • 文/花漫 我一把揭開白布僵缺。 她就那樣靜靜地躺著胡桃,像睡著了一般。 火紅的嫁衣襯著肌膚如雪磕潮。 梳的紋絲不亂的頭發(fā)上翠胰,一...
    開封第一講書人閱讀 52,549評論 1 312
  • 那天,我揣著相機與錄音自脯,去河邊找鬼之景。 笑死,一個胖子當著我的面吹牛膏潮,可吹牛的內(nèi)容都是我干的锻狗。 我是一名探鬼主播,決...
    沈念sama閱讀 41,063評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼焕参,長吁一口氣:“原來是場噩夢啊……” “哼轻纪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起叠纷,我...
    開封第一講書人閱讀 39,991評論 0 277
  • 序言:老撾萬榮一對情侶失蹤刻帚,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后涩嚣,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體崇众,經(jīng)...
    沈念sama閱讀 46,522評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,604評論 3 342
  • 正文 我和宋清朗相戀三年航厚,在試婚紗的時候發(fā)現(xiàn)自己被綠了顷歌。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,742評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡幔睬,死狀恐怖眯漩,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情溪窒,我是刑警寧澤坤塞,帶...
    沈念sama閱讀 36,413評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站澈蚌,受9級特大地震影響摹芙,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜宛瞄,卻給世界環(huán)境...
    茶點故事閱讀 42,094評論 3 335
  • 文/蒙蒙 一浮禾、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧份汗,春花似錦盈电、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至旁钧,卻和暖如春吸重,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背歪今。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評論 1 274
  • 我被黑心中介騙來泰國打工嚎幸, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人寄猩。 一個月前我還...
    沈念sama閱讀 49,159評論 3 378
  • 正文 我出身青樓嫉晶,卻偏偏與公主長得像,于是被迫代替她去往敵國和親田篇。 傳聞我的和親對象是個殘疾皇子替废,可洞房花燭夜當晚...
    茶點故事閱讀 45,747評論 2 361

推薦閱讀更多精彩內(nèi)容