SlideShare a Scribd company logo
1 of 64
Download to read offline
A productive Android development
environment
不只自動化而且更敏捷的Android開發工具 Gradle
Sam Chiu
Sam Chiu 邱炫儒
Sam Chiu@HTC engineering build dept.
promote DevOps in HTC
iamsamchiu@gmail.com / mindcraft4life.tumblr.com
Active Gradle Using Developers
500+
Software Components
1000+
Release Builds per Day
1000+
“ ”
The challenge of Mobile App development
If your App crashes for 0.01% of your users, they’re
going to post a negative review.
However, the 99.99% of people for whom it works great
are NOT going to post five-star ratings for the software
working as expected.
-- The Loop magazine
Automate everything
and shrink the cycle time
可重複運行 減少人為/環境錯誤 流程透明 產生更有品質的程式碼
Coding Check-in Build Test Publish
易於分享
Using Gradle...
put every new code commit through a
full cycle
Automated provisioning and
configuration management also part
of the continuous delivery
From Command line to IDE to CI
消除溝通的嫌隙
From Command line to IDE to CI
Convention 1
一句話惹毛老闆:
“我電腦沒這個問題呀!”
“It works on my machine!”
“一定有鬼偷偷動過我的程式碼”
使用不一致的工具
ant
proguard
shrink
resources
android
gradle plugin
build.xmlADT
eclipse
gradle
debug on/off
Source
Code
module
A
module
B
module
C
build failure
Those tools have different build
processes on your source code!
Android Studio/IntelliJ/..
gradle
減少溝通的嫌隙
From command line to IDE to continuous integration
proguard
shrink
resources
android gradle plugin
debug on/off
Coding with IDE
Building Automation
減少溝通的嫌隙
From command line to IDE to continuous integration
Android Studio
proguard
shrink
resources
android gradle plugin
gradle
debug on/off customized
configuration
generic
configuration
Source
Code
Source
Code
Source
Code
APK
ALPHA BETA RC
Project
Schedule
後期出現的錯誤往往影響巨大
將商業版本客製盡量提前到開發時期
Product Flavor and Multiple APK
Convention 2
<manifest ... >
<supports-screens android:smallScreens="false"
android:normalScreens="false"
android:largeScreens="true"
android:xlargeScreens="true"
android:requiresSmallestWidthDp="600"
/>
...
</manifest>
custom AndroidManifest.xml for tablet
Example on Google dev site:
Design Multi-APK for tablet and phone
Google Play
The versionName/versionCode schema for multiple APK
versionCode (04 01 310)
phone screen
App version(3.1.0)API Level(4+)
versionCode (04 02 310)
tablet screen
App version(3.1.0)API Level(4+)
release 1
upload
APKs
Version Name:
3.1.0-build1
Edit your versionCode in AndroidManifest.xml?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.testing.unittesting.BasicSample" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:versioncode="0401310"
android:versionName="3.1.0-build1" >
<activity
android:name="com.example.android.testing.unittesting.BasicSample.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
error-prone manual efforts around
deployment
把處理邏輯都編寫至gradle設定檔中
android{
defaultConfig {
versionName computeVersionName()
}
productFlavors {
phone{ versionCode computeVersionCode(1) }
tablet { versionCode computeVersionCode(2) }
}
}
def computeVersionCode(int flavor) {
def version_code = ext.minSdkVersion * 100000 + flavor * 1000 + ext.versionMajor * 100 + ext.versionMinor*10 
+ ext.versionIncremental
return version_code
}
def computeVersionName(){
def buildNumber = System.getenv("BUILD_NUMBER") ?: "dev"
def version_name = ext.versionMajor+"."+ext.versionMinor+”.”+ext.versionIncremental+"-"+buildNumber
return version_name
}
custom build logic and integrate with Jenkins
build.gradle:
為什麼要把Jenkins buildNumber 寫進
version name?
混在一起做撒尿牛丸?
為什麼要把Jenkins buildNumber 寫進
version name?
混在一起做Dogfooding
What is Dogfooding?
Dogfooding means a good product versioning
Library
Source
Project
Source
alpha 1 beta1Debug APK
Release 2Release APK
beta2
Release 1
alpha 1 beta2
OTA
Issue Tracking bug report
Release 2
OTAPRELOAD
Employee Device
透過Jenkins追朔程式碼
versionName
3.1.0-Build#2
Q:
處理邏輯要寫在gradle script 還是
寫在CI Server script?
寫在CI Server script的處理邏輯如何管理?
期待 jenkins 2.0
pipeline as code !
what is “pipeline as code”:https://wiki.jenkins-ci.org/display/JENKINS/2.0+Pipeline+as+Code
java code preprocessing
Convention 3
public final static boolean MY_DEBUG = false;
@Override
public void onConnectionFailed(ConnectionResult result) {
if (MY_DEBUG){
Log.i(TAG, "[Security sensitive Log] GoogleClient connection failed." );
Log.i(TAG, "[Security sensitive Log] UserName: "+UserName );
Log.i(TAG, "[Security sensitive Log] InternalModelName: "+InternalModelName );
}else{
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
}
每次專案定義可能都不同大家都需要去記Flag
增加自動化的複雜度
adjust consts to switch debug on/off
What is bad
直接修改程式碼
error-prone manual efforts around
deployment AGAIN!
Use BuildConfig in gradle
public final static boolean MY_DEBUG = false;
@Override
public void onConnectionFailed(ConnectionResult result) {
if (BuildConfig.DEBUG){
Log.i(TAG, "[Security sensitive Log] GoogleClient connection failed." );
Log.i(TAG, "[Security sensitive Log] UserName: "+UserName );
Log.i(TAG, "[Security sensitive Log] InternalModelName: "+InternalModelName );
}else{
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
}
編譯時期無需修改程式碼
$ gradlew assembleRelease
$ gradlew assembleDebug
Customize BuildConfig in gradle
buildTypes {
debug {
buildConfigField "boolean","NETWORK_DEBUG","true"
minifyEnabled false
}
release {
buildConfigField "boolean","NETWORK_DEBUG","false"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
從
程式碼管理
到
組態管理
Convention 4
“By distributing your project source based on
gradle ,anyone can work with it without needing to
install many annoying tools/dependencies
beforehand”
“Users of the build are guaranteed to use the same
process and the same dependencies version that
was designed to work with”
from http://gradle.org/
SCM (git)
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
Use .gitignore
建立可重複且可靠的流程
Build script as code
Build Once and build anywhere
Why upload shell/batch files to
version control server?
gradlew.sh
gradle wrapper
#Sun Aug 09 19:57:07 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.5-all.zip
gradle-wrapper.properties
Even better!
Install android-sdk automatically
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.example.android.testing.unittesting.BasicSample"
minSdkVersion 17
targetSdkVersion 23
}
}
Reference: https://github.com/JakeWharton/sdk-manager-plugin
gradle project on git
pure Mac OS
Java
source code
build script
dependencies
configuration
toolchain
configuration
Maven Repo
toolchain sites
google play service
facebook sdk lib
firebase sdk lib
...
gradle tool
android sdk
pure Windows
Java
less administration and more scalable for the client machines
gradle 2.4
gradle 2.5
build-tool 19
build-tool 20
platforms 19
platforms 23
pure linux
Java
pure linux
Java
pure linux
Java
...
developers machines Continuous Integration servers
install tools on build time
Dependencies Management
Convention 5
root project
lib-proj
widget
lib-proj
Activity
firebase
sdk
facebook
sdk
evernote
sdk
dropbox
sdk
Google play service libgoogle
support v4
log/util
module
drive
Google+
games
analytics
Location
Ads
maps
nearby
wallet
google support
appcompat-v7
google support
design lib
google support
multidex
google support
multidex instrumentation
A large scale Android App
root project
lib-proj
widget
lib-proj
Activity
firebase
sdk
evernote
sdk
dropbox
sdk
Google play service libgoogle
support v4
log/util
module
drive
Google+
games
analytics
Location
Ads
maps
nearby
wallet
google support
appcompat-v7
google support
design lib
google support
multidex
google support
multidex instrumentation
facebook
sdk
The dependency nightmare
Before Gradle
Getting started with the Dropbox Android SDK:
1. Include everything under lib/ in your project/build.
2. You'll want to start off by creating an
AndroidAuthSession with your consumer key and secret.
3...
Download dropbox-android-sdk from dropbox website
1
2
到底用了哪一版library?
┌Top Android Project
│
├── Project 1 - (Pure Java Modules)
│ │
│ ├── Module A1
│ │ └──libs/android-support-v4_22.jar
│ ├── Module B1
│ :
│ └── facebook-lib-project
│ └──libs/android-support-v4-v22.0.0.jar
│
BUILD FAIL
After Gradle
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
1. Use gradle
2.
3. That’s it.
dependencies {
compile 'com.google.android.gms:play-services-wearable:7.3.0'
}
How about the depend on a tree of dependencies?
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
dependencies {
compile 'com.google.android.gms:play-services-wearable:7.3.0'
}
android-support-v4:21.0.0
android-support-v4:22.0.0
Transitive Dependencies on Gradle(可遞移性相依)
A -> B and B -> C
hence A -> C
google play service aar library hierarchy on maven
Tips of transitive dependencies
dependencies {
compile 'com.google.android.gms:play-services-wearable:7.3.0'
}
dependencies {
compile 'com.google.android.gms:play-services-wearable:7.3.0
@aar'
}
android-support-v4:22.0.0
android-support-v4:22.0.0
transitive=false
As a library provider
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services-location</artifactId>
<version>7.8.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services-maps</artifactId>
<version>7.8.0</version>
<scope>compile</scope>
<type>aar</type>
</dependency>
…...
Maven Repository
HelloWorld Library/pom.xml
remember to provide your transitive
dependencies in pom.xml
Handle dependency conflict
Gradle offers the following conflict resolution strategies:
Newest: The newest version of the dependency is used. This is Gradle's default strategy,
and is often an appropriate choice as long as versions are backwards-compatible.
Fail: A version conflict results in a build failure. This strategy requires all version
conflicts to be resolved explicitly in the build script.
Use ‘Fail’ resolution strategy
configurations.all {
resolutionStrategy {
// fail eagerly on version conflict (includes transitive dependencies)
// e.g. multiple different versions of the same dependency (group and name are equal)
failOnVersionConflict()
}
}
build.gradle:
Handle dependency conflict
dependencies {
compile('org.hibernate:hibernate:3.1') {
//in case of versions conflict '3.1' version of hibernate wins:
force = true
//disabling all transitive dependencies of this dependency
transitive = false
}
}
build.gradle:
Versioning Control
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.+'
}
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.1.0-SNAPSHOT'
}
建置系統始終應該指定專案所需外部類別庫的確切版本 :
開發時期指定專案所需外部函式庫的最新版本 :
開發時期指定專案所需外部函式庫的 SNAPSHOT版本:
about testing
Convention 6
Building Effective Testing plan
Unit test
● mokito
● Robolectric
Integration test (acceptance testing)
● Instrumentation
● emulation
○ Genymotion (local with virtualBox)
○ Manymo (online)
● online device testing
○ appthwack (AWS Cloud)
Repeatable
- 可在任何環境下進行測試(沒有網路、db、Android Context的狀況下仍能進行)
Purpose
- 讓單元測試運行速度加快,可加速回饋,更可了解自己的修改是否破壞現有的任
何功能。
How
- 單元測試依存於測試替身,不應該存取資料庫、檔案系統、與外部系統互動。
- 簡單來說,單元測試不應該與系統元件之間產生互動。
A unit test should be “Repeatable”
Building Effective Unit Tests
Unit test
● mokito
● Robolectric
put every new code commit through a full cycle!
Integration test (acceptance testing)
● Instrumentation
● emulation
○ Genymotion (local with virtualBox)
○ Manymo (online)
● online device testing
○ appthwack (AWS Cloud)
測試策略的設計主要是個「識別和評估專案風險之優先順序及
決定採用哪些行動來緩解風險」的歷程
Test Case Strategy
--Continuous Delivery:reliable software rleases though build, test and deployment automation
測試策略的設計主要是個「識別和評估專案風險之優先順序及
決定採用哪些行動來緩解風險」的歷程
Test Case Strategy
--Continuous Delivery:reliable software rleases though build, test and deployment automation
未慮勝 先慮敗
Example: com.facebook.login.widget.LoginButtonTest.java
@Test
public void testLoginButtonWithReadPermissions() throws Exception {
LoginManager loginManager = mock(LoginManager.class);
Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();
LoginButton loginButton = (LoginButton) activity.findViewById(R.id.login_button);
ArrayList<String> permissions = new ArrayList<>();
permissions.add("user_location");
loginButton.setReadPermissions(permissions);
loginButton.setDefaultAudience(DefaultAudience.EVERYONE);
loginButton.setLoginManager(loginManager);
loginButton.performClick();
verify(loginManager).logInWithReadPermissions(activity, permissions);
verify(loginManager, never()).logInWithPublishPermissions(isA(Activity.class), anyCollection());
// Verify default audience is channeled
verify(loginManager).setDefaultAudience(DefaultAudience.EVERYONE);
}
Reference: https://github.com/facebook/facebook-android-sdk
com.facebook.login.widget.LoginButton.java
private class LoginClickListener implements OnClickListener {
@Override
public void onClick(View v) {
…
if (LoginAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
loginManager.logInWithPublishPermissions(LoginButton.this.getActivity(),properties.permissions);
} else {
loginManager.logInWithReadPermissions(LoginButton.this.getActivity(),properties.permissions);
//[sam] demo unit test
//loginManager.logInWithPublishPermissions(LoginButton.this.getActivity(),properties.permissions);
}
}
Command-line Option
enable continuous build with the -t or –continuous command-line option which
will automatically re-execute builds when changes are detected to its inputs.
ex:
reference:
http://gradle.org/feature-spotlight-continuous-build/
speed up your build-edit-build feedback loop
$ gradlew test -t
From handcrafted
to mindcrafted
Q&A
Reference:
● Android plugin for gradle:
https://developer.android.com/tools/building/plugin-for-gradle.html:
● Android tools project site, tips:
http://tools.android.com/tech-docs/new-build-system/tips
● Gradle dependency management:
https://docs.gradle.org/current/userguide/dependency_management.html
● Google dev site, multiple apk:
https://developer.android.com/google/play/publishing/multiple-apks.html
● Sample project on github:
https://github.com/iamsamchiu/AndroidSampleForGradleUsage
The Android robot is modified from work created by Google/StockLogos and used according to the Creative Commons 3.0 Attribution License.

More Related Content

What's hot

Spark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopSpark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopArun Gupta
 
Comparing JVM Web Frameworks - Rich Web Experience 2010
Comparing JVM Web Frameworks - Rich Web Experience 2010Comparing JVM Web Frameworks - Rich Web Experience 2010
Comparing JVM Web Frameworks - Rich Web Experience 2010Matt Raible
 
Running Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesVMware Tanzu
 
Peering Inside the Black Box: A Case for Observability
Peering Inside the Black Box: A Case for ObservabilityPeering Inside the Black Box: A Case for Observability
Peering Inside the Black Box: A Case for ObservabilityVMware Tanzu
 
JPQL/ JPA Activity 1
JPQL/ JPA Activity 1JPQL/ JPA Activity 1
JPQL/ JPA Activity 1SFI
 
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019Matt Raible
 
How to Win at UI Development in the World of Microservices - THAT Conference ...
How to Win at UI Development in the World of Microservices - THAT Conference ...How to Win at UI Development in the World of Microservices - THAT Conference ...
How to Win at UI Development in the World of Microservices - THAT Conference ...Matt Raible
 
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020Matt Raible
 
Exploring the GitHub Service Universe
Exploring the GitHub Service UniverseExploring the GitHub Service Universe
Exploring the GitHub Service UniverseBjörn Kimminich
 
Continuous integration using jenkins
Continuous integration using jenkinsContinuous integration using jenkins
Continuous integration using jenkinsVinay H G
 
"How to deploy to production 10 times a day" Андрей Шумада
"How to deploy to production 10 times a day" Андрей Шумада"How to deploy to production 10 times a day" Андрей Шумада
"How to deploy to production 10 times a day" Андрей ШумадаFwdays
 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOTVMware Tanzu
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for androidzhang ghui
 
Getting started with Jenkins
Getting started with JenkinsGetting started with Jenkins
Getting started with JenkinsEdureka!
 
Going Serverless Using the Spring Framework Ecosystem
Going Serverless Using the Spring Framework EcosystemGoing Serverless Using the Spring Framework Ecosystem
Going Serverless Using the Spring Framework EcosystemVMware Tanzu
 
SpringOne Platform recap 정윤진
SpringOne Platform recap 정윤진SpringOne Platform recap 정윤진
SpringOne Platform recap 정윤진VMware Tanzu Korea
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
 
Making the most of your gradle build - vJUG24 2017
Making the most of your gradle build - vJUG24 2017Making the most of your gradle build - vJUG24 2017
Making the most of your gradle build - vJUG24 2017Andres Almiray
 
Making the most of your gradle build - BaselOne 2017
Making the most of your gradle build - BaselOne 2017Making the most of your gradle build - BaselOne 2017
Making the most of your gradle build - BaselOne 2017Andres Almiray
 

What's hot (20)

Spark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopSpark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 Workshop
 
Comparing JVM Web Frameworks - Rich Web Experience 2010
Comparing JVM Web Frameworks - Rich Web Experience 2010Comparing JVM Web Frameworks - Rich Web Experience 2010
Comparing JVM Web Frameworks - Rich Web Experience 2010
 
Running Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native ImagesRunning Spring Boot Applications as GraalVM Native Images
Running Spring Boot Applications as GraalVM Native Images
 
Peering Inside the Black Box: A Case for Observability
Peering Inside the Black Box: A Case for ObservabilityPeering Inside the Black Box: A Case for Observability
Peering Inside the Black Box: A Case for Observability
 
JPQL/ JPA Activity 1
JPQL/ JPA Activity 1JPQL/ JPA Activity 1
JPQL/ JPA Activity 1
 
OpenMIC March-2012.phonegap
OpenMIC March-2012.phonegapOpenMIC March-2012.phonegap
OpenMIC March-2012.phonegap
 
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
 
How to Win at UI Development in the World of Microservices - THAT Conference ...
How to Win at UI Development in the World of Microservices - THAT Conference ...How to Win at UI Development in the World of Microservices - THAT Conference ...
How to Win at UI Development in the World of Microservices - THAT Conference ...
 
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020
Mobile Development with Ionic, React Native, and JHipster - AllTheTalks 2020
 
Exploring the GitHub Service Universe
Exploring the GitHub Service UniverseExploring the GitHub Service Universe
Exploring the GitHub Service Universe
 
Continuous integration using jenkins
Continuous integration using jenkinsContinuous integration using jenkins
Continuous integration using jenkins
 
"How to deploy to production 10 times a day" Андрей Шумада
"How to deploy to production 10 times a day" Андрей Шумада"How to deploy to production 10 times a day" Андрей Шумада
"How to deploy to production 10 times a day" Андрей Шумада
 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
Getting started with Jenkins
Getting started with JenkinsGetting started with Jenkins
Getting started with Jenkins
 
Going Serverless Using the Spring Framework Ecosystem
Going Serverless Using the Spring Framework EcosystemGoing Serverless Using the Spring Framework Ecosystem
Going Serverless Using the Spring Framework Ecosystem
 
SpringOne Platform recap 정윤진
SpringOne Platform recap 정윤진SpringOne Platform recap 정윤진
SpringOne Platform recap 정윤진
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Making the most of your gradle build - vJUG24 2017
Making the most of your gradle build - vJUG24 2017Making the most of your gradle build - vJUG24 2017
Making the most of your gradle build - vJUG24 2017
 
Making the most of your gradle build - BaselOne 2017
Making the most of your gradle build - BaselOne 2017Making the most of your gradle build - BaselOne 2017
Making the most of your gradle build - BaselOne 2017
 

Viewers also liked

How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speedFate Chang
 
實用分析工具 Amplitude / 分析工具hub - Segment
實用分析工具 Amplitude / 分析工具hub - Segment實用分析工具 Amplitude / 分析工具hub - Segment
實用分析工具 Amplitude / 分析工具hub - SegmentWu Wells
 
Gradle and build systems for C language
Gradle and build systems for C languageGradle and build systems for C language
Gradle and build systems for C languageJuraj Michálek
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenArnaud Héritier
 
Captain Agile and the Providers of Value
Captain Agile and the Providers of ValueCaptain Agile and the Providers of Value
Captain Agile and the Providers of ValueSchalk Cronjé
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...ZeroTurnaround
 
20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache MavenArnaud Héritier
 
Building Android apps with Maven
Building Android apps with MavenBuilding Android apps with Maven
Building Android apps with MavenFabrizio Giudici
 
Veni, Vide, Built: Android Gradle Plugin
Veni, Vide, Built: Android Gradle PluginVeni, Vide, Built: Android Gradle Plugin
Veni, Vide, Built: Android Gradle PluginLeonardo YongUk Kim
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android projectShaka Huang
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenArnaud Héritier
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 

Viewers also liked (20)

Gradle by Example
Gradle by ExampleGradle by Example
Gradle by Example
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speed
 
實用分析工具 Amplitude / 分析工具hub - Segment
實用分析工具 Amplitude / 分析工具hub - Segment實用分析工具 Amplitude / 分析工具hub - Segment
實用分析工具 Amplitude / 分析工具hub - Segment
 
Gradle and build systems for C language
Gradle and build systems for C languageGradle and build systems for C language
Gradle and build systems for C language
 
Alpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache MavenAlpes Jug (29th March, 2010) - Apache Maven
Alpes Jug (29th March, 2010) - Apache Maven
 
Captain Agile and the Providers of Value
Captain Agile and the Providers of ValueCaptain Agile and the Providers of Value
Captain Agile and the Providers of Value
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven
 
Building Android apps with Maven
Building Android apps with MavenBuilding Android apps with Maven
Building Android apps with Maven
 
Maven 3.0 at Øredev
Maven 3.0 at ØredevMaven 3.0 at Øredev
Maven 3.0 at Øredev
 
Veni, Vide, Built: Android Gradle Plugin
Veni, Vide, Built: Android Gradle PluginVeni, Vide, Built: Android Gradle Plugin
Veni, Vide, Built: Android Gradle Plugin
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android project
 
Gradle
GradleGradle
Gradle
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 

Similar to 不只自動化而且更敏捷的Android開發工具 gradle mopcon

Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the CloudSimona Cotin
 
de:code 2019 DT06 vs-show どっちのVSショー
de:code 2019 DT06 vs-show どっちのVSショーde:code 2019 DT06 vs-show どっちのVSショー
de:code 2019 DT06 vs-show どっちのVSショーIssei Hiraoka
 
Continuous Delivery With Selenium Grid And Docker
Continuous Delivery With Selenium Grid And DockerContinuous Delivery With Selenium Grid And Docker
Continuous Delivery With Selenium Grid And DockerBarbara Gonzalez
 
Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewelljwi11iams
 
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGContinuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGJakub Pyda
 
Continuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyContinuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyKamil Kochański
 
Agile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery WorkshopAgile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery WorkshopMichael Palotas
 
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkinsdevopsdaysaustin
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginXavier Hallade
 
Aws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, ImplementationAws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, Implementationserkancapkan
 
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...Henning Jacobs
 
Grunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierGrunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierErick Brito
 
Codecoon - A technical Case Study
Codecoon - A technical Case StudyCodecoon - A technical Case Study
Codecoon - A technical Case StudyMichael Lihs
 
Continuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsContinuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsEvgeniy Kuzmin
 
WSO2Con EU 2015: Keynote - The Containerization of the Developer Workspace
WSO2Con EU 2015: Keynote - The Containerization of the Developer WorkspaceWSO2Con EU 2015: Keynote - The Containerization of the Developer Workspace
WSO2Con EU 2015: Keynote - The Containerization of the Developer WorkspaceWSO2
 
Continuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsContinuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsSunil Dalal
 
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build TimesUsing Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build TimesDevOps.com
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made EasyAlon Fliess
 
Ci/CD - Stop wasting time, Automate your deployments
Ci/CD  - Stop wasting time, Automate your deploymentsCi/CD  - Stop wasting time, Automate your deployments
Ci/CD - Stop wasting time, Automate your deploymentsJerry Jalava
 

Similar to 不只自動化而且更敏捷的Android開發工具 gradle mopcon (20)

Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
 
de:code 2019 DT06 vs-show どっちのVSショー
de:code 2019 DT06 vs-show どっちのVSショーde:code 2019 DT06 vs-show どっちのVSショー
de:code 2019 DT06 vs-show どっちのVSショー
 
Continuous Delivery With Selenium Grid And Docker
Continuous Delivery With Selenium Grid And DockerContinuous Delivery With Selenium Grid And Docker
Continuous Delivery With Selenium Grid And Docker
 
Intro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler JewellIntro to Eclipse Che, by Tyler Jewell
Intro to Eclipse Che, by Tyler Jewell
 
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGContinuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
 
Continuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyContinuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case Study
 
Agile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery WorkshopAgile Bodensee - Testautomation & Continuous Delivery Workshop
Agile Bodensee - Testautomation & Continuous Delivery Workshop
 
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
 
Aws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, ImplementationAws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, Implementation
 
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...
Why we don’t use the Term DevOps: the Journey to a Product Mindset - DevOpsCo...
 
Grunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierGrunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End Tier
 
Codecoon - A technical Case Study
Codecoon - A technical Case StudyCodecoon - A technical Case Study
Codecoon - A technical Case Study
 
gopaddle-meetup
gopaddle-meetupgopaddle-meetup
gopaddle-meetup
 
Continuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsContinuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applications
 
WSO2Con EU 2015: Keynote - The Containerization of the Developer Workspace
WSO2Con EU 2015: Keynote - The Containerization of the Developer WorkspaceWSO2Con EU 2015: Keynote - The Containerization of the Developer Workspace
WSO2Con EU 2015: Keynote - The Containerization of the Developer Workspace
 
Continuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsContinuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applications
 
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build TimesUsing Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Ci/CD - Stop wasting time, Automate your deployments
Ci/CD  - Stop wasting time, Automate your deploymentsCi/CD  - Stop wasting time, Automate your deployments
Ci/CD - Stop wasting time, Automate your deployments
 

不只自動化而且更敏捷的Android開發工具 gradle mopcon

  • 1. A productive Android development environment 不只自動化而且更敏捷的Android開發工具 Gradle Sam Chiu
  • 2. Sam Chiu 邱炫儒 Sam Chiu@HTC engineering build dept. promote DevOps in HTC iamsamchiu@gmail.com / mindcraft4life.tumblr.com Active Gradle Using Developers 500+ Software Components 1000+ Release Builds per Day 1000+
  • 3. “ ” The challenge of Mobile App development
  • 4. If your App crashes for 0.01% of your users, they’re going to post a negative review. However, the 99.99% of people for whom it works great are NOT going to post five-star ratings for the software working as expected. -- The Loop magazine
  • 5. Automate everything and shrink the cycle time 可重複運行 減少人為/環境錯誤 流程透明 產生更有品質的程式碼 Coding Check-in Build Test Publish 易於分享
  • 6. Using Gradle... put every new code commit through a full cycle Automated provisioning and configuration management also part of the continuous delivery From Command line to IDE to CI
  • 7. 消除溝通的嫌隙 From Command line to IDE to CI Convention 1
  • 11. Android Studio/IntelliJ/.. gradle 減少溝通的嫌隙 From command line to IDE to continuous integration proguard shrink resources android gradle plugin debug on/off Coding with IDE Building Automation
  • 12. 減少溝通的嫌隙 From command line to IDE to continuous integration Android Studio proguard shrink resources android gradle plugin gradle debug on/off customized configuration generic configuration Source Code Source Code Source Code APK ALPHA BETA RC Project Schedule
  • 15. Product Flavor and Multiple APK Convention 2
  • 16. <manifest ... > <supports-screens android:smallScreens="false" android:normalScreens="false" android:largeScreens="true" android:xlargeScreens="true" android:requiresSmallestWidthDp="600" /> ... </manifest> custom AndroidManifest.xml for tablet Example on Google dev site: Design Multi-APK for tablet and phone
  • 17. Google Play The versionName/versionCode schema for multiple APK versionCode (04 01 310) phone screen App version(3.1.0)API Level(4+) versionCode (04 02 310) tablet screen App version(3.1.0)API Level(4+) release 1 upload APKs Version Name: 3.1.0-build1
  • 18. Edit your versionCode in AndroidManifest.xml? <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.testing.unittesting.BasicSample" > <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:versioncode="0401310" android:versionName="3.1.0-build1" > <activity android:name="com.example.android.testing.unittesting.BasicSample.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> error-prone manual efforts around deployment
  • 20. android{ defaultConfig { versionName computeVersionName() } productFlavors { phone{ versionCode computeVersionCode(1) } tablet { versionCode computeVersionCode(2) } } } def computeVersionCode(int flavor) { def version_code = ext.minSdkVersion * 100000 + flavor * 1000 + ext.versionMajor * 100 + ext.versionMinor*10 + ext.versionIncremental return version_code } def computeVersionName(){ def buildNumber = System.getenv("BUILD_NUMBER") ?: "dev" def version_name = ext.versionMajor+"."+ext.versionMinor+”.”+ext.versionIncremental+"-"+buildNumber return version_name } custom build logic and integrate with Jenkins build.gradle:
  • 21. 為什麼要把Jenkins buildNumber 寫進 version name? 混在一起做撒尿牛丸?
  • 22. 為什麼要把Jenkins buildNumber 寫進 version name? 混在一起做Dogfooding
  • 24. Dogfooding means a good product versioning Library Source Project Source alpha 1 beta1Debug APK Release 2Release APK beta2 Release 1 alpha 1 beta2 OTA Issue Tracking bug report Release 2 OTAPRELOAD Employee Device
  • 27. 寫在CI Server script的處理邏輯如何管理? 期待 jenkins 2.0 pipeline as code ! what is “pipeline as code”:https://wiki.jenkins-ci.org/display/JENKINS/2.0+Pipeline+as+Code
  • 29. public final static boolean MY_DEBUG = false; @Override public void onConnectionFailed(ConnectionResult result) { if (MY_DEBUG){ Log.i(TAG, "[Security sensitive Log] GoogleClient connection failed." ); Log.i(TAG, "[Security sensitive Log] UserName: "+UserName ); Log.i(TAG, "[Security sensitive Log] InternalModelName: "+InternalModelName ); }else{ Log.i(TAG, "GoogleApiClient connection failed: " + result.toString()); } 每次專案定義可能都不同大家都需要去記Flag 增加自動化的複雜度 adjust consts to switch debug on/off What is bad 直接修改程式碼 error-prone manual efforts around deployment AGAIN!
  • 30. Use BuildConfig in gradle public final static boolean MY_DEBUG = false; @Override public void onConnectionFailed(ConnectionResult result) { if (BuildConfig.DEBUG){ Log.i(TAG, "[Security sensitive Log] GoogleClient connection failed." ); Log.i(TAG, "[Security sensitive Log] UserName: "+UserName ); Log.i(TAG, "[Security sensitive Log] InternalModelName: "+InternalModelName ); }else{ Log.i(TAG, "GoogleApiClient connection failed: " + result.toString()); } 編譯時期無需修改程式碼 $ gradlew assembleRelease $ gradlew assembleDebug
  • 31. Customize BuildConfig in gradle buildTypes { debug { buildConfigField "boolean","NETWORK_DEBUG","true" minifyEnabled false } release { buildConfigField "boolean","NETWORK_DEBUG","false" minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
  • 33. “By distributing your project source based on gradle ,anyone can work with it without needing to install many annoying tools/dependencies beforehand” “Users of the build are guaranteed to use the same process and the same dependencies version that was designed to work with” from http://gradle.org/
  • 35. Build Once and build anywhere Why upload shell/batch files to version control server?
  • 36. gradlew.sh gradle wrapper #Sun Aug 09 19:57:07 CST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https://services.gradle.org/distributions/gradle-2.5-all.zip gradle-wrapper.properties
  • 37. Even better! Install android-sdk automatically apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion '22.0.1' defaultConfig { applicationId "com.example.android.testing.unittesting.BasicSample" minSdkVersion 17 targetSdkVersion 23 } } Reference: https://github.com/JakeWharton/sdk-manager-plugin
  • 38. gradle project on git pure Mac OS Java source code build script dependencies configuration toolchain configuration Maven Repo toolchain sites google play service facebook sdk lib firebase sdk lib ... gradle tool android sdk pure Windows Java less administration and more scalable for the client machines gradle 2.4 gradle 2.5 build-tool 19 build-tool 20 platforms 19 platforms 23 pure linux Java pure linux Java pure linux Java ... developers machines Continuous Integration servers install tools on build time
  • 40. root project lib-proj widget lib-proj Activity firebase sdk facebook sdk evernote sdk dropbox sdk Google play service libgoogle support v4 log/util module drive Google+ games analytics Location Ads maps nearby wallet google support appcompat-v7 google support design lib google support multidex google support multidex instrumentation A large scale Android App
  • 41. root project lib-proj widget lib-proj Activity firebase sdk evernote sdk dropbox sdk Google play service libgoogle support v4 log/util module drive Google+ games analytics Location Ads maps nearby wallet google support appcompat-v7 google support design lib google support multidex google support multidex instrumentation facebook sdk The dependency nightmare
  • 42. Before Gradle Getting started with the Dropbox Android SDK: 1. Include everything under lib/ in your project/build. 2. You'll want to start off by creating an AndroidAuthSession with your consumer key and secret. 3... Download dropbox-android-sdk from dropbox website 1 2
  • 43. 到底用了哪一版library? ┌Top Android Project │ ├── Project 1 - (Pure Java Modules) │ │ │ ├── Module A1 │ │ └──libs/android-support-v4_22.jar │ ├── Module B1 │ : │ └── facebook-lib-project │ └──libs/android-support-v4-v22.0.0.jar │ BUILD FAIL
  • 44. After Gradle dependencies { compile 'com.facebook.android:facebook-android-sdk:4.1.0' } 1. Use gradle 2. 3. That’s it. dependencies { compile 'com.google.android.gms:play-services-wearable:7.3.0' }
  • 45. How about the depend on a tree of dependencies? dependencies { compile 'com.facebook.android:facebook-android-sdk:4.1.0' } dependencies { compile 'com.google.android.gms:play-services-wearable:7.3.0' } android-support-v4:21.0.0 android-support-v4:22.0.0
  • 46. Transitive Dependencies on Gradle(可遞移性相依) A -> B and B -> C hence A -> C
  • 47. google play service aar library hierarchy on maven
  • 48. Tips of transitive dependencies dependencies { compile 'com.google.android.gms:play-services-wearable:7.3.0' } dependencies { compile 'com.google.android.gms:play-services-wearable:7.3.0 @aar' } android-support-v4:22.0.0 android-support-v4:22.0.0 transitive=false
  • 49. As a library provider <?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <groupId>com.google.android.gms</groupId> <artifactId>play-services-location</artifactId> <version>7.8.0</version> <packaging>aar</packaging> <dependencies> <dependency> <groupId>com.google.android.gms</groupId> <artifactId>play-services-maps</artifactId> <version>7.8.0</version> <scope>compile</scope> <type>aar</type> </dependency> …... Maven Repository HelloWorld Library/pom.xml remember to provide your transitive dependencies in pom.xml
  • 50. Handle dependency conflict Gradle offers the following conflict resolution strategies: Newest: The newest version of the dependency is used. This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible. Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script.
  • 51. Use ‘Fail’ resolution strategy configurations.all { resolutionStrategy { // fail eagerly on version conflict (includes transitive dependencies) // e.g. multiple different versions of the same dependency (group and name are equal) failOnVersionConflict() } } build.gradle:
  • 52. Handle dependency conflict dependencies { compile('org.hibernate:hibernate:3.1') { //in case of versions conflict '3.1' version of hibernate wins: force = true //disabling all transitive dependencies of this dependency transitive = false } } build.gradle:
  • 53. Versioning Control dependencies { compile 'com.facebook.android:facebook-android-sdk:4.1.0' } dependencies { compile 'com.facebook.android:facebook-android-sdk:4.1.+' } dependencies { compile 'com.facebook.android:facebook-android-sdk:4.1.0-SNAPSHOT' } 建置系統始終應該指定專案所需外部類別庫的確切版本 : 開發時期指定專案所需外部函式庫的最新版本 : 開發時期指定專案所需外部函式庫的 SNAPSHOT版本:
  • 55. Building Effective Testing plan Unit test ● mokito ● Robolectric Integration test (acceptance testing) ● Instrumentation ● emulation ○ Genymotion (local with virtualBox) ○ Manymo (online) ● online device testing ○ appthwack (AWS Cloud)
  • 56. Repeatable - 可在任何環境下進行測試(沒有網路、db、Android Context的狀況下仍能進行) Purpose - 讓單元測試運行速度加快,可加速回饋,更可了解自己的修改是否破壞現有的任 何功能。 How - 單元測試依存於測試替身,不應該存取資料庫、檔案系統、與外部系統互動。 - 簡單來說,單元測試不應該與系統元件之間產生互動。 A unit test should be “Repeatable”
  • 57. Building Effective Unit Tests Unit test ● mokito ● Robolectric put every new code commit through a full cycle! Integration test (acceptance testing) ● Instrumentation ● emulation ○ Genymotion (local with virtualBox) ○ Manymo (online) ● online device testing ○ appthwack (AWS Cloud)
  • 60. Example: com.facebook.login.widget.LoginButtonTest.java @Test public void testLoginButtonWithReadPermissions() throws Exception { LoginManager loginManager = mock(LoginManager.class); Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); LoginButton loginButton = (LoginButton) activity.findViewById(R.id.login_button); ArrayList<String> permissions = new ArrayList<>(); permissions.add("user_location"); loginButton.setReadPermissions(permissions); loginButton.setDefaultAudience(DefaultAudience.EVERYONE); loginButton.setLoginManager(loginManager); loginButton.performClick(); verify(loginManager).logInWithReadPermissions(activity, permissions); verify(loginManager, never()).logInWithPublishPermissions(isA(Activity.class), anyCollection()); // Verify default audience is channeled verify(loginManager).setDefaultAudience(DefaultAudience.EVERYONE); } Reference: https://github.com/facebook/facebook-android-sdk
  • 61. com.facebook.login.widget.LoginButton.java private class LoginClickListener implements OnClickListener { @Override public void onClick(View v) { … if (LoginAuthorizationType.PUBLISH.equals(properties.authorizationType)) { loginManager.logInWithPublishPermissions(LoginButton.this.getActivity(),properties.permissions); } else { loginManager.logInWithReadPermissions(LoginButton.this.getActivity(),properties.permissions); //[sam] demo unit test //loginManager.logInWithPublishPermissions(LoginButton.this.getActivity(),properties.permissions); } }
  • 62. Command-line Option enable continuous build with the -t or –continuous command-line option which will automatically re-execute builds when changes are detected to its inputs. ex: reference: http://gradle.org/feature-spotlight-continuous-build/ speed up your build-edit-build feedback loop $ gradlew test -t
  • 64. Reference: ● Android plugin for gradle: https://developer.android.com/tools/building/plugin-for-gradle.html: ● Android tools project site, tips: http://tools.android.com/tech-docs/new-build-system/tips ● Gradle dependency management: https://docs.gradle.org/current/userguide/dependency_management.html ● Google dev site, multiple apk: https://developer.android.com/google/play/publishing/multiple-apks.html ● Sample project on github: https://github.com/iamsamchiu/AndroidSampleForGradleUsage The Android robot is modified from work created by Google/StockLogos and used according to the Creative Commons 3.0 Attribution License.