惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
C
Cisco Blogs
The Hacker News
The Hacker News
T
Tor Project blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
Vercel News
Vercel News
C
CERT Recently Published Vulnerability Notes
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
I
Intezer
aimingoo的专栏
aimingoo的专栏
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
P
Proofpoint News Feed
P
Proofpoint News Feed
B
Blog
T
Threat Research - Cisco Blogs
博客园 - 叶小钗
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Schneier on Security
Schneier on Security
N
News | PayPal Newsroom
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
GRAHAM CLULEY

CrazyWong

香港銀行開戶推薦 (附邀請碼) CrazyWong AI LOGO 🎧 Anson Seabra - Keep Your Head Up Princess 是的,我又更換了域名 1.5 萬字 CSS 基礎拾遺(核心知識、常見需求) JavaScript - 日期 Date JavaScript - 數組 Array 域名更換 前端 JavaScript 自測清單 2 前端 JavaScript 自測清單 1 通過travis-ci或者GitHub Actions自動化部署GitHub Pages和Coding Pages 添加Windows Terminal到鼠標右鍵菜單 調研實現高性能動畫 在瀏覽器輸入 URL 回車之後發生了什麼(超詳細版) hexo-theme-butterfly 安裝文檔(一)快速開始 設置Windows電腦自動關機 Windows必裝軟件推薦 關於字符編碼,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…) 好用的新浪圖床工具推薦 - Weibo-Picture-Store Java知識點複習(二) Java知識點複習(一) Visual Studio Code 插件推薦-VSC Netease Music 重裝系統後重新部署恢復 Hexo blog Windows上Java的環境變量配置 Adapter 9Patch 介紹 第一行代碼筆記-RecyclerView 為Blog添加版權説明 第一行代碼筆記-ListView 第一行代碼筆記-創建自定義控件 第一行代碼筆記-四大Layout Hexo和Next主題的相關設置(持續更新) 第一行代碼筆記-Android Studio工程目錄結構介紹 第一行代碼筆記-工具日志log
第一行代碼筆記-bulid.gradle 解析
MYW · 2018-06-08 · via CrazyWong

外層的bulid.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
buildscript {
    repositories {
        jcenter()  
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
       
       
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

兩處的repositories的閉包中都聲明了jcenter() 這行配置。
jcenter是一個代碼托管倉庫,很多Androdi開源項目都會選擇將代碼托管到jcenter上,聲明了這個配置之後,可以在項目中引用任何jcenter上的開源項目。

dependencies閉包使用classpath聲明一個gradle插件。gradle并不是專門為構建android項目而開發,使用它時,需要聲明com.android.tools.build:gradle+版本號

app目錄内的build.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25    
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.hwy01.myfirstapp"  
        minSdkVersion 15  
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {    
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies
{  
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

第一行是應用了一個插件,一般有2個值可選:

  • com.android.application表示這是一個應用程序模塊
  • com.android.library 表示這是一個庫模塊。

應用程序模塊和庫模塊的最大區別是,一個可以直接運行,一個衹能作爲代碼庫依附于別的應用程序模塊來運行。

buildTypes閉包用於指定生成安裝文件的相關配置。通常衹有2個子閉包:debug和release

  • debug閉包用於指定生成測試版安裝文件的配置
  • release閉包用於指定生成正式版安裝文件的配置
    debug閉包可以忽略不寫。

release閉包詳解

  • minifyEnabled 用於指定是否對對項目的代碼進行混淆。 true表示混淆,false表示不混淆。
  • proguardFiles用於指定混淆時使用的規則文件。

proguard-android.txt 是在Android SDK目錄下的,裏面是所有項目通用的混淆規則。
proguard-rules.pro 是在當前項目根目錄下的,裏面可以編寫當前項目特有的混淆規則

通過Android Studio直接運行項目生成的都是測試版安裝文件

dependencies閉包 指定當前項目所有的依賴關係

通常Android Studio項目一共有3種依賴方式:

  • 本地依賴

可以對本地的jar包或目錄添加依賴關係

  • 庫依賴

可以對項目中的庫模塊添加依賴關係

  • 遠程依賴

可以對jcenter庫上的開源項目添加依賴關係

compile 'com.android.support:appcompat-v7:25.2.0' 標準的遠程依賴庫格式
com.android.support是域名部分,用於和其他公司的庫做區分。
appcompat-v7是組名稱,用於和同一個公司中不同的庫做區分。
25.2.0是版本號,用於和同一個庫不同的版本做區分。

版權聲明: 本部落格所有文章除特別聲明外,均採用CC BY-NC-SA 4.0 授權協議。轉載請註明來源 CrazyWong