Giter Site home page Giter Site logo

olivierperez / android-shortcut-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zellius/android-shortcut-gradle-plugin

0.0 3.0 0.0 88 KB

Android Gradle plugin generates App Shortcuts shortcuts.xml for build flavors with different applicationId.

License: MIT License

Java 9.72% Groovy 90.28%

android-shortcut-gradle-plugin's Introduction

android-shortcut-gradle-plugin

Android Gradle plugin generates App Shortcuts shortcuts.xml for build flavors with different applicationId.

When it useful?

If you look at the official documentation of static App Shortcuts, you'll see that for each intent you need to set the android:targetPackage. But what if you have different applicationId in different flavors?

android {
    defaultConfig {
        applicationId "ru.solodovnikov.shortcutgradlehelper"
    }
    productFlavors {
        dev {
            applicationIdSuffix "dev"
        }
        prod {
            applicationId "ru.solodovnikov.shortcut"
        }
    }
}

In this example you'll need copy your shortcuts.xml in two folder dev and prod with single difference. And if you create a new flavor with different applicationId you need to copy it again. Since at this moment we do not have any built-in merge tools applicationId from build.gradle to the shortcuts.xml this gradle plugin will be useful.

Example

  1. Create shortcuts.xml (or name it how you want) and put it in your project. Do not set any android:targetPackage.
  <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
      <shortcut android:shortcutId="test1" android:enabled="true" android:icon="@mipmap/ic_launcher"
          android:shortcutShortLabel="@string/app_name" android:shortcutLongLabel="@string/app_name"
          android:shortcutDisabledMessage="@string/app_name">
          <intent android:action="android.intent.action.VIEW"
              android:targetClass="ru.solodovnikov.shortcuthelper.MainActivity" />
          <intent android:action="android.intent.action.VIEW"
              android:targetClass="ru.solodovnikov.shortcuthelper.SecondActivity" />
          <categories android:name="android.shortcut.conversation" />
      </shortcut>
  </shortcuts>
  1. Apply android-shortcut-gradle-plugin.
buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'com.github.zellius:android-shortcut-gradle-plugin:0.1.1'
      }
}

apply plugin: 'com.android.application'
apply plugin: 'com.github.zellius.shortcut-helper'
  1. Set path to your shortcuts.xml.
shortcutHelper.filePath = '../shortcuts.xml'
  1. Set shortcuts.xml in your manifest.
<meta-data android:name="android.app.shortcuts"
           android:resource="@xml/shortcuts" />

Android Studio can mark @xml/shortcuts as "cannot resolve"...but it is ok :) 5. PROFIT!!!!

You can try an example from the repository.

android-shortcut-gradle-plugin's People

Contributors

olivierperez avatar zellius avatar

Watchers

 avatar  avatar  avatar

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.