简体   繁体   中英

How to set default libraries for all android studio projects

有一些库是android开发的关键部分。问题是,在制作一个新项目时,我们可以设置一些默认库添加到gradle中吗(我知道有些方法,例如模板,但它们在某种程度上也需要相同的过程)

In AndroidStudio there are some templates.
You can manage them to add some dependencies, but I discourage this way since the templates can change in the later releases, each update can override your files, then it is not so simple to have a good maintenance.

It is not equivalent and may be it not your aim but you can copy an external gradle file in your projects and then just add the dependencies in a very short time.

Something like gradleScript/dependecies.gradle

ext {
    //Version
    supportLibrary = '27.x.x'

    //Support Libraries dependencies
    supportDependencies = [
            design           :         "com.android.support:design:${supportLibrary}",
            recyclerView     :         "com.android.support:recyclerview-v7:${supportLibrary}",
            cardView         :         "com.android.support:cardview-v7:${supportLibrary}",
            appCompat        :         "com.android.support:appcompat-v7:${supportLibrary}",
            supportAnnotation:         "com.android.support:support-annotations:${supportLibrary}",
    ]
}

Add in your top-level build.gradle :

// Load dependencies
apply from: 'gradleScript/dependencies.gradle'

And then in each module/build.gradle just add your dependencies:

// Module build file

dependencies {
    //......
    compile supportDependencies.appCompat
    compile supportDependencies.design
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM