as gradle新版本 引入第三方库_build.gradle 新版本 maven plugins id 'com.android.app-优快云博客
项目创建的时候想引入github上的第三方库,结果发现项目目录下build.gradle中buildscript等都不见了,
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
以前的样子:
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven { url 'https://dl.bintray.com/umsdk/release'}
maven { url 'https://repo1.maven.org/maven2/'}
google()
mavenCentral()
mavenLocal()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven{url"https://maven.google.com"}
jcenter()
mavenCentral()
mavenLocal()
maven{url 'https://jitpack.io'}
maven { url 'https://dl.bintray.com/umsdk/release'}
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
maven { url 'https://repo1.maven.org/maven2/'}
google()
mavenCentral()
mavenLocal()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
compileSdkVersion = 29
buildToolsVersion = '29.0.0'
minSdkVersion = 21
targetSdkVersion = 29
supportLibraryVersion = '29.0.0'
}
其实像以前一样就行:
先在app目录下,implementation你要引入的包
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//比如引用这个
implementation 'com.github.freyskill:SerialPortHelper:v1.0.1'
}
然后在项目目录下settings.gradle里面加入:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
}
rootProject.name = "Tesd"
include ':app'
如果需要classpath的话:在项目的build.gradle里面,放在plugins上面:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
//比如这个
classpath 'com.android.tools.build:gradle:7.0.3'
}
}
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这样就和以前一样了。