program story

build.gradle (Project)와 build.gradle (Module)의 차이점

inputbox 2020. 9. 17. 07:52
반응형

build.gradle (Project)와 build.gradle (Module)의 차이점


내 프로젝트에 Android 비동기 Http 클라이언트의 종속성을 추가하려고합니다. 따라서 프로젝트에는 두 개의 build.gradle 파일이 있습니다.

여기에 이미지 설명 입력

내 이해에 따라 다른 종류의 종속성이 있습니다.

  1. build.gradle (Project : My-app)의 루트 레벨에 정의 된 것
  2. build.gradle (Project : My-app)의 buildscript 안에있는 하나
  3. 다른 하나는 build.gradle (Modules : app)

이 질문 은 buildScript의 종속성에 대한 리포지토리에 관한 것이며 처음 두 유형에 대해 약간 설명합니다.

또한 build.gradle (Project : My-app)은 말합니다.

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

그래서 Android Asynchronous Http Client의 종속성 코드가 build.gradle (Module : app)에 추가되어야한다고 생각합니다.

누군가가 더 나은 이해를 위해이 모든 것을 명확하게 보여줄 수 있다면 좋을 것입니다.


build.gradle(Project:My-app)

모든 하위 프로젝트 / 모듈에 공통적 인 구성 옵션을 추가 할 수있는 최상위 빌드 파일입니다.

각 프로젝트에는top-level gradle file . 그것은 일반적 common configs으로 모든 modules. 여기에 포함 된 내용이 무엇이든 top-level gradle모두에게 영향을 미칩니다 modules.

전의:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha3'

        //Maven plugin
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(Module:app)

특정 모듈의 빌드 파일 (종속성, 서명 구성, 빌드 유형, 특징 등을 추가하는 위치)

모두 modules특정 gradle파일이 있습니다. gradle파일에 포함 된 내용은 포함 된에 영향을줍니다 module.

전의:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.hrskrs.gesturefun"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            zipAlignEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            zipAlignEnabled true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':gesture-fun')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
}

Android Studio는 기본적으로 두 build.gradle파일을 서로 바로 옆에 표시하기 때문에 약간 혼란 스럽습니다 (Android보기를 사용할 때).

여기에 이미지 설명 입력

If you switch to the Project view you can see the actual structure and where the different build.gradle files are located.

여기에 이미지 설명 입력

The build.gradle (Project: MyApplication) file is in the root folder of the project and its configuration settings apply to every module in the project. A module is an isolated piece of the bigger project. In a multi-module project, these modules have their own jobs but work together to form the whole project. Most Android projects only have one module, the app module.

The build.gradle (Module: app) file here is in the app folder. Its build settings apply only to the app module. If there were another module, then that module would have its own build.gradle file, too. As an example, I made a library project with three modules: a library module, a demo app module, and another app module that I plan to use for testing. Each of them have their own build.gradle files that I can tweak.

여기에 이미지 설명 입력

In a basic project, almost everything you need to edit will be in the app module's build.gradle file. You can remember it like this:

You're making an app, so go to the build.gradle (Module: app) file.

Further reading


About relation of the two gradle files, hrskrs made a very clear explanation,I will make some supplement about it.

if your project only has one Module (such as app),the advantage of top build.gradle(Project:My-app) not show very clear. because you can config everything in build.gradle(Module:app) about the Module,and only modify one file when upgrade in following days。

but if your project has 5 Modules,and it happened that they have a same dependence A, if you dont use the top build.gradle(Project:My-app) you need maintain 5 files in following days.

그건 그렇고, build.gradle (Module : app)build.gradle (Project : My-app)을 덮어 쓸 수 있습니다 .

이 디자인은 APP의 유지 보수성을 향상시킬 수 있습니다.

참고 URL : https://stackoverflow.com/questions/28295933/difference-between-build-gradleproject-and-build-gradlemodule

반응형