Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Adding SDK versions and dependencies to all module [duplicate]

In my currently working project contains lot of modules and dependency. So is there is any way to keep all this versions and dependency common and reuse in all modules. I know that we can define common dependency in root build.gradle file but whats about things like compileSdkVersions and exclude groups. My dependency some times include exclude group like.

  androidTestCompile ('com.android.support.test:rules:1.0.1'){
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'
}

How can we handle this scenario? Once we have add in root build.gradle, Is there any way to add them all in a app module with out specifying individual ones like below.

compile deps.cardview
compile deps.design
compile deps.supportv4
compile deps.animation
compile deps.pagination
compile deps.shimmerlayout
compile deps.enhanced_card
compile deps.swipeanim
compile deps.appcompact
like image 847
Ebin Joy Avatar asked Dec 03 '25 20:12

Ebin Joy


1 Answers

For things like compileSdkVersion, buildTypes and compileOptions, I define sth like this in root gradle file :

ext.android_settings_for_module = {
    compileSdkVersion COMPIlE_SDK_VERSION.toInteger()
    buildToolsVersion BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion 
        targetSdkVersion 
        versionCode 
        versionName 
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
    }
    compileOptions compile_options
    lintOptions lint_options
    testOptions test_options
}

ext.lint_options = {
    //butterKnife
    disable 'InvalidPackage'
}

ext.compile_options = {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

And then, in your module file, you can use :

android android_settings_for_module

Quite Similar for dependencies. Define a field in root gradle file :

ext.common_libs = [

]

And then use in module level gradle file :

dependencies {
    compile common_libs
}
like image 192
Yash Avatar answered Dec 05 '25 09:12

Yash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!