Android studio 根目录build.gradle增加三方库

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
}

这样就和以前一样了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值