アンドロイド:Gradleのクイックスタート

1、Gradleのは何ですか?

Gradleの持つアリ/ Mavenのは、依存関係の管理/自動化されたビルドツールです。アリ/ Mavenのは同じではありませんと。しかし、それは特定のフィールドのGroovy(DSL)は、Javaベースのアプリケーションのための言語で置き換え内部に基づいて、XMLのさまざまな基づいて複雑な構成を放棄しました。これより、シンプルな柔軟でより強力であり、Mavenとツタと完全に互換性のGradleます。

詳細は、公式ウェブサイト上で見ることができます。http://www.gradle.org/

2、なぜ?

  • より強力なコードヒントや操作しやすいです。
  • 設定が簡単に拡張。
  • より強力な依存関係の管理、バージョン管理
  • より良い統合IDE

 GradleでAS

ファイルのディレクトリ構造

プロジェクトの下build.gradle

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

buildscript {
    //指定远程中央仓库
    repositories {
        google()
        //jcenter指向的是: https://jcenter.bintray.com/,兼容maven中心仓库,性能更优
        jcenter()
        
    }
    //指定整个工程的依赖
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
//所有工程及其modle都使用jcenter、google中央仓库
allprojects {
    repositories {
        google()
        jcenter()
        
    }
}
//执行delete构建时, 删除工程下所有构建产生的文件夹
task clean(type: Delete) {
    delete rootProject.buildDir
}

モジュール下的build.gradle

// 声明是Android程序
apply plugin: 'com.android.application'

android {
    // 指定编译SDK的版本
    compileSdkVersion 28
    defaultConfig {
        // 应用的包名
        applicationId "com.example.recyclerdome"
        //最小版本
        minSdkVersion 16
        //目标版本
        targetSdkVersion 28
        versionCode 1
        //应用版本号
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            // 是否进行代码混淆
            minifyEnabled false
            // 混淆配置文件的位置
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
//包含所有依赖的jar或库
dependencies {
    // 编译libs目录下的所有jar包
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    //测试时才编译junit包
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
}

settings.gradle  // このファイルには、グローバルなプロジェクトの設定ファイルであります

Gradleのフォルダとそのサブフォルダ

含みます

Gradleでは、wrapper.jar

gradle-wrapper.properties

これら二つがあるGradleの2つの必要なファイルが作成プロジェクトが自動的に生成され我々は変更する必要はありません

公開された71元の記事 ウォン称賛19 ビュー10000 +

おすすめ

転載: blog.csdn.net/qq_39131246/article/details/101901788