GithubHelp home page GithubHelp logo

821104180 / injector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from artyomd/injector

0.0 1.0 0.0 1.99 MB

Gradle plugin for android which makes easier to inject aar libraries into project

License: Apache License 2.0

Java 98.91% Shell 1.09%

injector's Introduction

Injector

Maven Central Codacy Badge Known Vulnerabilities

Injector is a gradle plugin for android projects which helps to make third-party android libraries downloadable. Injector supports android gradle plugin 3.1.0+. For more information and background of Injector you can read this article.

How it works

Injector plugin extracts all aar files into build/exploded-aar directory then, merges all manifests to your project's manifest, copies all resources into your project's resource directory, generates R.java for aar libraries, compiles them and injects classes into library's class.jar and then creates dex files from jar files.

How to use

Injector consists of two parts: gradle plugin (to create dex files from aar and jar files) and android library (to load dex files)

How to create dex files

Add maven central repository to your project's build script and add injector library to your classpath app.artyomd.injector:injector:{latest-version} . Your build script should look like the following

buildscript {
    repositories {
        google()
	mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'app.artyomd.injector:injector:{latest-version}'
    }
}

After this, you can just apply plugin: 'app.artyomd.injector' in you android library module and use inject configuration to inject other libraries into your project. Injector also provides a configuration closure to exclude libraries with group/name and specify dex file location. Default location of dex file is build/outputs/inject/inject.dex. To generate dex file you must run of the following tasks createInjectDebugDexes or createInjectReleaseDexes

injectConfig{
    enabled = true
	excludeGroups = ["com.foo.*", "bar.foo.*"]
	groups = [
            "X": ["foo.bar.*"]
    ]
    dexLocation = "/outputs/inject/inject.dex"
}

By default, we are excluding android libs such as com.android., android.arch., etc.

With this inject config you will get X.dex and inject.dex files in /outputs/inject/ directory and that dex files will not contain classes which packages are "com.foo.", "bar.foo." and X.dex will only conatn classes which packages are "foo.bar.*".

How to load dex files at runtime

Injector also provides android helper library to inject dex files. Add maven central repository to your project dependencies and add "app.artyomd.injector:injector-android:{latest-version}" in your dependencies

repositories {
        google()
	mavenCentral()
        jcenter()
    }
dependencies {
    implementation "app.artyomd.injector:injector-android:{latest-version}"
}

You can upload dex file to somewhere and then at runtime download and load it or copy dex file to assets folder then at runtime copy the file into internal storage and then load dex file. If your dex files are in the assets dir just use DexUtils.prepareDex to copy dex files into internal storage. Using DexUtils.loadDex you can load a list of dex files into your application at runtime.

Disclaimer

An app distributed via Google Play may not modify, replace, or update itself using any method other than Google Play's update mechanism. Likewise, an app may not download executable code (e.g. dex, JAR, .so files) from a source other than Google Play. This restriction does not apply to code that runs in a virtual machine and has limited access to Android APIs (such as JavaScript in a webview or browser). Source

Be aware that downloading executable code from an application may affect the removal of your application from Google Play.

injector's People

Contributors

artyomd avatar dependabot-support avatar dependabot-preview[bot] avatar jbeguna04 avatar cililing avatar jileshl avatar codacy-badger avatar

Watchers

James Cloos 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.