前言
最近想使用一個開源框架AndServer,根據(jù)文檔說明,首先需要在Project下的build.gradle做如下配置:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.yanzhenjie.andserver:plugin:2.1.10'
...
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
...
但是我的項目下的build.gradle長得是這樣子的:
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
納尼?怎么buildscript和allprojects閉包都不見了?那我還怎么配置?
查閱了一下官方文檔,原來是2022年1月的Gradle7.1.0版本做的更新導致的,如下圖:
如果你用的是小蜜蜂版本的Android Studio,創(chuàng)建的的項目,默認就是沒有buildscript和allprojects的,之前的倉庫配置被挪到Project下的setting.gradle里面了。
解決辦法
說了那么多,好像也沒提到我所要關心的內(nèi)容:要怎么配置“classpath ‘com.yanzhenjie.andserver:plugin:2.1.10’”?
其實依舊可以放在Project下的build.gradle里面,完整的配置如下:
buildscript {
dependencies {
classpath 'com.yanzhenjie.andserver:plugin:2.1.10'
}
}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
注意buildscript閉包需要放在plugins閉包前面,不然會報錯。好了,這下已經(jīng)達成了我的目的。
補充
我的module下的build.gradle如下:文章來源:http://www.zghlxwxcb.cn/news/detail-417836.html
plugins {
id 'com.android.application'
}
apply plugin: 'com.yanzhenjie.andserver'
android {
compileSdk 31
defaultConfig {
applicationId "com.example.lyyserverdemo"
minSdk 21
targetSdk 31
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.yanzhenjie.andserver:api:2.1.10'
annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.10'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
就是在頂部加了apply plugin: ‘com.yanzhenjie.andserver’,以及在底部的依賴里加了
implementation ‘com.yanzhenjie.andserver:api:2.1.10’
annotationProcessor ‘com.yanzhenjie.andserver:processor:2.1.10’
這是根據(jù)AndServer文檔配置的,接下來就可以使用這個框架了。文章來源地址http://www.zghlxwxcb.cn/news/detail-417836.html
到了這里,關于AndroidStudio中Project下的build.gradle沒有buildscript和allprojects了的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!