Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
不只自動化而且更敏捷的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+
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
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
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
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
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/
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
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
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
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:
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)
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.