默认在Android Studio Bumblebee 基于Gradle7.1创建项目引入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是这样设置的
- 项目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'
}
开始尝试在项目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搜索了下有这些回答:
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'
}
才编译通过。