Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Continuous Deploy no Android

Continuous Deploy no Android

Júlio Zynger

April 12, 2016
Tweet

More Decks by Júlio Zynger

Other Decks in Programming

Transcript

  1. Continuous Deploy no
    Android
    Júlio Zynger

    View full-size slide

  2. Deploy Contínuo?

    View full-size slide

  3. http://bit.ly/cd_codeship

    View full-size slide

  4. http://bit.ly/cd_codeship

    View full-size slide

  5. http://bit.ly/cd_codeship

    View full-size slide

  6. Configuração do console

    View full-size slide

  7. Google Developer Console
    Habilitar a Google Play Android Developer API *
    * crie um projeto no developer console se já não houver um com APIs configuradas
    * painel Visão Geral do console
    https://console.developers.google.com/apis

    View full-size slide

  8. Google Developer Console
    Obtendo a service account key
    * painel Credenciais do console
    https://console.developers.google.com/apis

    View full-size slide

  9. Google Developer Console
    JSON da chave
    https://console.developers.google.com/apis

    View full-size slide

  10. Google Developer Console
    JSON da chave
    https://console.developers.google.com/apis

    View full-size slide

  11. Google Developer Console
    secret.pem *
    https://console.developers.google.com/apis
    * substituição de \n por nova linha

    View full-size slide

  12. Google Play Store Console
    Vincular o acesso à API
    https://play.google.com/apps/publish

    View full-size slide

  13. Google Play Store Console
    Adicionar conta de serviço
    https://play.google.com/apps/publish
    * vincule o email do campo client_email no JSON da chave

    View full-size slide

  14. O Android Publisher

    View full-size slide

  15. Google Play Developer API *
    ● Subscriptions and In-App Purchases API
    ○ In-App Products
    ○ Status de produtos comprados
    ○ Produtos recorrentes e subscriptions
    ● Publishing API
    ○ Criação e modificação dos Listings de seu app
    ○ Upload de novas versões do APK
    ○ Atribuição de APKs às Tracks do Google Play (alpha, beta, staged rollout e produção)
    * Limite de 200 mil requisições por dia

    View full-size slide

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

    View full-size slide

  17. Configurando a dependência
    Download da biblioteca
    compile 'com.google.apis:google-api-services-androidpublisher:v2-rev30-
    1.22.0'
    http://bit.ly/androidpublisher_maven
    https://developers.google.com/android-publisher/#publishing

    View full-size slide

  18. Configurando a dependência
    Instanciando o 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

    View full-size slide

  19. Configurando a dependência
    Instanciando o 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)

    View full-size slide

  20. Configurando a dependência
    Instanciando o 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

    View full-size slide

  21. Configurando a dependência
    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

    View full-size slide

  22. Configurando a dependência
    AppEdits - validate e 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

    View full-size slide

  23. Configurando a dependência
    AppEdits - validate e 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."
    }

    View full-size slide

  24. Configurando a dependência
    AppEdits - Listings
    Edits edits = publisher.edits();
    Listings listings = edits.listings();
    ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute();
    // Selecionar o Listing que vai ser atualizado
    Listing listing = listingsListResponse.getListings().get(...)
    listing.setFullDescription(description);
    listings.update(PACKAGE, transactionId, language, listing).execute();
    // ... validate
    // ... commit
    https://developers.google.com/android-publisher/#publishing

    View full-size slide

  25. Configurando a dependência
    AppEdits - Listings
    Edits edits = publisher.edits();
    Listings listings = edits.listings();
    ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute();
    // Selecionar o Listing que vai ser atualizado
    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" : "This app is a simple demo
    application for developers who
    are interested in continuous
    deploy in the android platform.",
    "language" : "en-US",
    "shortDescription" : "Demo application for
    developers",
    "title" : "Continuous Deploy Demo App",
    "video" : ""
    }

    View full-size slide

  26. Configurando a dependência
    AppEdits - upload do 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

    View full-size slide

  27. Configurando a dependência
    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

    View full-size slide

  28. Configurando a dependência
    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” (com userFraction),
    “production”

    View full-size slide

  29. Configurando a dependência
    AppEdits - APKListings
    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

    View full-size slide

  30. Continuous Delivery
    De um git push para
    produção
    bit.ly/googlepublisher_jenkins
    bit.ly/googlepublisher_gradle

    View full-size slide

  31. Continuous Delivery
    De um git push para
    produção
    bit.ly/googlepublisher_jenkins
    bit.ly/googlepublisher_gradle

    View full-size slide

  32. https://github.com/julioz/continuousdeploydemo

    View full-size slide

  33. http://bit.ly/android-continuous-deploy-post

    View full-size slide