Git Product home page Git Product logo

gradle-drive's Introduction

gradle-drive

Lightweight gradle plugin to upload your APK to the Google Drive. Needs the com.android.application plugin applied.

Quick Start Guide

  1. Create new project on Google Developers Console (or use existing one).
  2. Enable Drive API in API Manager (see Prerequisites).
  3. Create Google Service Account for that project (see Prerequisites).
  4. Share target Google Drive folder with service account email or make it public (see [Drive Folder]).
  5. Add the plugin to your buildscript dependencies (see Usage).
  6. Apply the plugin (see Usage).
  7. Apply your credentials inside the drive block (see Credentials).

Prerequisites

Project at Google Developers Console

You need to have a project at https://console.developers.google.com/iam-admin/projects to be able to access Google APIs.

Enabling Drive API

You can enable Drive API at API Manager https://console.developers.google.com/apis/dashboard. You can skip warning about credencials or click "Create credencials" button and use wizard to create required stuff. When you use wizard choose Other non-UI from dropdown menu and select Application Data access. For next steps see Prerequisites

Google Service Account

To use this plugin you have to create a service account and generate private .p12 key (.json authorization may be added in future). Just click create service account button, check Furnish a new private key and select P12 option. Save generated p12 key file and service account email address we will use them later on.

Give Drive Folder Access to the service account

Google doesn't allow you to access Drive folders for your service account directly, but there is some workaround. You can create folder in your account's Drive and share access to service account email. After that you can use that folder id setting it as a parent for service account uploads. This is secure way to access uploaded files. You can also make your folder a folder with public access (less secure, not tested).

Usage

Add it to your buildscript dependencies: (Artifactory not working yet! For temporary solution see below)

buildscript {

    repositories {
        // using github packages
        maven {
            name = "GithubPackages"
            url = uri("https://maven.pkg.github.com/monsterbrain/gradle-drive")
            credentials {
                username = "monsterbrain"
                password = "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"
            }
        }
    }

    dependencies {
    	// ...
        classpath 'com.github.ximik:drive:1.1'
    }
}

Apply it:

apply plugin: 'com.github.ximik3.drive'

The plugin creates the following tasks for you:

  • uploadApkDebug - Uploads APK file signed with temporary debug keys.
  • uploadApkRelease - Uploads APK file signed with actual keys.

Make sure to set a valid signingConfig for the release build type. Otherwise, there won't be a release APK and the uploadApkRelease won't be available.

In case you are using product flavors you will get one of the above tasks for every flavor. E.g. uploadApkQaRelease or uploadProductionRelease.

Configuration

Once you have applied this plugin to your android application project you can configure it via the drive block.

Credentials

Drop in your service account email address and the p12 key file (key.p12 file should be in app folder) you generated in the API Console here. folderId will be last part of google drive link (drive.google.com/drive/folders/folderId)

drive {
    serviceAccountEmail = 'your-service-account-email'
    pk12File = file('key.p12')
    folderId = 'your-shared-folder-id'
}

Advanced Topics

Run Upload after Assemble apk

For automatically running upload task after assemble Task you can configure it like this

afterEvaluate {
    assembleRelease.configure {
        finalizedBy uploadApkRelease
    }
}

Assemble apk before uploading

Before running above tasks you need to be sure that you have required .apk file assembled and stored under app/build/outputs/apk folder, otherwise task will fail with java.io.FileNotFoundExeption. For example, you can run:

./gradlew assembleDebug

and only after successful build run:

./gradlew uploadApkDebug

Inspired by https://github.com/Triple-T/gradle-play-publisher .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.