Slide 1

Slide 1 text

Publishing API and Continuous Deployment Júlio Zynger

Slide 2

Slide 2 text

Continuous Deployment?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

http://bit.ly/cd_codeship

Slide 5

Slide 5 text

http://bit.ly/cd_codeship

Slide 6

Slide 6 text

http://bit.ly/cd_codeship

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Google Play Developer API

Slide 9

Slide 9 text

Google Play Developer API * ● Subscriptions and In-App Purchases API ○ In-App Products ○ Product entitlements ○ Recurring sales and subscriptions ● Publishing API ○ Create and modify apps’ Listings ○ Upload new APKs ○ APK promotion to distribution tracks (alpha, beta, staged rollout and production) ● Reviews API ○ List and answer reviews * quota: 200k requests/day

Slide 10

Slide 10 text

Console configuration

Slide 11

Slide 11 text

Google Developer Console Enabling Google Play Android Developer API * * create a project on the console if you haven’t yet * panel Library https://console.developers.google.com/apis

Slide 12

Slide 12 text

Google Developer Console Getting the service account key * panel Credentials https://console.developers.google.com/apis

Slide 13

Slide 13 text

Google Developer Console JSON key https://console.developers.google.com/apis

Slide 14

Slide 14 text

Google Developer Console JSON key https://console.developers.google.com/apis

Slide 15

Slide 15 text

Google Developer Console secret.pem * https://console.developers.google.com/apis * replace character \n with new line

Slide 16

Slide 16 text

Google Play Store Console Link the app to the created project to access the API https://play.google.com/apps/publish

Slide 17

Slide 17 text

Google Play Store Console Grant access to the service account https://play.google.com/apps/publish * check out for the address present on the client_email field in the JSON key

Slide 18

Slide 18 text

Android Publisher

Slide 19

Slide 19 text

developers.google.com/android-publisher/api-ref/

Slide 20

Slide 20 text

Configuring the dependency compile 'com.google.apis:google-api-services-androidpublisher:v2-rev41-1.22.0' http://bit.ly/androidpublisher_maven https://developers.google.com/android-publisher/#publishing

Slide 21

Slide 21 text

Configuring the dependency Instantiating GoogleCredential NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory json = JacksonFactory.getDefaultInstance(); Set scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER); File secretFile = new File(Constants.SECRET_FILE_PATH); GoogleCredential credential = new GoogleCredential.Builder(). setTransport(http). setJsonFactory(json). setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountScopes(scopes). setServiceAccountPrivateKeyFromPemFile(secretFile). build(); https://developers.google.com/android-publisher/#publishing

Slide 22

Slide 22 text

Configuring the dependency Instantiating GoogleCredential NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory json = JacksonFactory.getDefaultInstance(); Set scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER); File secretFile = new File(Constants.SECRET_FILE_PATH); GoogleCredential credential = new GoogleCredential.Builder(). setTransport(http). setJsonFactory(json). setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountScopes(scopes). setServiceAccountPrivateKeyFromPemFile(secretFile). build(); https://developers.google.com/android-publisher/#publishing setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountPrivateKeyFromPemFile(secretFile). private_key_id client_email private_key (.pem)

Slide 23

Slide 23 text

Configuring the dependency Instantiating AndroidPublisher NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory json = JacksonFactory.getDefaultInstance(); GoogleCredential credential = ... AndroidPublisher publisher = new AndroidPublisher.Builder(http, json, credential). setApplicationName(PACKAGE). build(); https://developers.google.com/android-publisher/#publishing

Slide 24

Slide 24 text

AppEdits AndroidPublisher publisher = ... Edits edits = publisher.edits(); // insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... https://developers.google.com/android-publisher/#publishing

Slide 25

Slide 25 text

AppEdits validate and commit AndroidPublisher publisher = ... Edits edits = publisher.edits(); // insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... edits.validate(PACKAGE, transactionId).execute(); edits.commit(PACKAGE, transactionId).execute(); https://developers.google.com/android-publisher/#publishing

Slide 26

Slide 26 text

AppEdits validate and commit AndroidPublisher publisher = ... Edits edits = publisher.edits(); // insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... edits.validate(PACKAGE, transactionId).execute(); edits.commit(PACKAGE, transactionId).execute(); https://developers.google.com/android-publisher/#publishing { "code" : 403, "errors" : [ { "domain" : "androidpublisher", "message" : "The full description for the app is too long for language en-US.", "reason" : "fullDescriptionTooLong" } ], "message" : "The full description for the app is too long for language en-US." }

Slide 27

Slide 27 text

AppEdits Listings Edits edits = publisher.edits(); Listings listings = edits.listings(); ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute(); // Select the Listing you want to update Listing listing = listingsListResponse.getListings().get(...) listing.setFullDescription(description); listings.update(PACKAGE, transactionId, language, listing).execute(); // ... validate // ... commit https://developers.google.com/android-publisher/#publishing

Slide 28

Slide 28 text

AppEdits Listings Edits edits = publisher.edits(); Listings listings = edits.listings(); ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute(); // Select the Listing you want to update Listing listing = listingsListResponse.getListings().get(...) listing.setFullDescription(description); listings.update(PACKAGE, transactionId, language, listing).execute(); // ... validate // ... commit https://developers.google.com/android-publisher/#publishing { "fullDescription" : string, "language" : string // e.g. "en-US", "shortDescription" : string, "title" : string, "video" : string }

Slide 29

Slide 29 text

AppEdits Uploading a new APK Apks apks = edits.apks(); FileContent apkContent = new FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); https://developers.google.com/android-publisher/#publishing

Slide 30

Slide 30 text

AppEdits Tracks Apks apks = edits.apks(); FileContent apkContent = new FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); https://developers.google.com/android-publisher/#publishing

Slide 31

Slide 31 text

AppEdits Tracks Apks apks = edits.apks(); FileContent apkContent = new FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); https://developers.google.com/android-publisher/#publishing “alpha”, “beta”, “rollout” (with userFraction), “production”

Slide 32

Slide 32 text

AppEdits APKListing Apks apks = edits.apks(); FileContent apkContent = new FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); Apklistings apklistings = edits.apklistings(); ApkListing whatsnew = new ApkListing().setRecentChanges(whatsNewDescription); apklistings.update(PACKAGE, transactionId, version, language, whatsnew).execute(); https://developers.google.com/android-publisher/#publishing

Slide 33

Slide 33 text

Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ... ... https://developers.google.com/android-publisher/#publishing

Slide 34

Slide 34 text

Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ... ... https://developers.google.com/android-publisher/#publishing { "reviewId" : string, "authorName" : string, "comments" : [ "userComment" : { "text" : string, "starRating" : int, "device" : string, "androidOsVersion" : integer, ... }, "developerComment" : { ... } ] }

Slide 35

Slide 35 text

Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ReviewsReplyRequest replyRequest = new ReviewsReplyRequest().setReplyText(replyText); reviewsApi.reply(PACKAGE, reviewId, replyRequest).execute(); ... ... https://developers.google.com/android-publisher/#publishing

Slide 36

Slide 36 text

Continuous Delivery From git push to production bit.ly/googlepublisher_jenkins bit.ly/googlepublisher_gradle

Slide 37

Slide 37 text

https://github.com/julioz/continuousdeploydemo

Slide 38

Slide 38 text

Thanks! about.me/ julioz linkedin.com/in/ juliozynger twitter.com/ juliozynger github.com/ julioz medium.com/@juliozynger