zoukankan      html  css  js  c++  java
  • RePlugin 插件化-内置加载

    PS:插件化是什么这里就不再说了,从这里开始两种加载方式中的一种(内置加载),该框架是奇虎360开发的,官方给出优点

    RePlugin是一套完整的、稳定的、适合全面使用的,占坑类插件化方案。我们“逐词”拆开来解释这个定义:
    
    完整的:让插件运行起来“像单品那样”,支持大部分特性
    稳定的:如此灵活完整的情况下,其框架崩溃率仅为业内很低的“万分之一”
    适合全面使用的:其目的是让应用内的“所有功能皆为插件”
    占坑类:以稳定为前提的Manifest占坑思路
    插件化方案:基于Android原生API和语言来开发,充分利用原生特性
    

    简单使用

    加载方式

    • 内置加载
    • 外置加载

    内置加载

    1:在项目根目录的 build.gradle 下添加 RePlugin Host Gradle 依赖:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
            // 1、添加RePlugin Host Gradle依赖
            classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.1'
        }
    }
    

    2:在 app/build.gradle 下添加 RePlugin Host Library 依赖

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 26
        buildToolsVersion "26.0.1"
        defaultConfig {
            applicationId "cn.codingblock.repluginstudy"
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    //有用
    apply plugin: 'replugin-host-gradle'// 集成 RePlugin 添加的配置
    
    // 集成 RePlugin 添加的配置
    repluginHostConfig {
        useAppCompat = true // 如果项目需要支持 AppComat,则需要将此配置置为 true
        // 如果应用需要个性化配置坑位数量,则需要添加以下代码进行配置
    //    countNotTranslucentStandard = 6
    //    countNotTranslucentSingleTop = 2
    //    countNotTranslucentSingleTask = 3
    //    countNotTranslucentSingleInstance = 2
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:26.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.qihoo360.replugin:replugin-host-lib:2.2.1' // 集成 RePlugin 添加的配置
        testCompile 'junit:junit:4.12'
    }
    

    3:让工程的 Application 直接继承自 RePluginApplication

    不继承的如下

    public class MyApplication extends Application {
    
        @Override
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            RePlugin.App.attachBaseContext(this);
        }
    
        @Override
        public void onCreate() {
            super.onCreate();
            RePlugin.App.onCreate();
        }
    
        @Override
        public void onLowMemory() {
            super.onLowMemory();
            RePlugin.App.onLowMemory();
        }
    
        @Override
        public void onTrimMemory(int level) {
            super.onTrimMemory(level);
            RePlugin.App.onTrimMemory(level);
        }
    
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            RePlugin.App.onConfigurationChanged(newConfig);
        }
    }
    

    在 AndroidManifest 对 MyApplication 的相关配置

    插件apk项目创建

    4:根目录的 build.gradle 添加 RePlugin Plugin Gradle 依赖(若是单独创建插件工程,则不需要添加注释1下面的代码):

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
            // 1、添加RePlugin Host Gradle依赖(主工程用)
            classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.1'
            // 2、添加RePlugin Plugin Gradle依赖(插件工程用)
            classpath 'com.qihoo360.replugin:replugin-plugin-gradle:2.2.1'
        }
    }
    

    5:在 app/build.gradle 中添加 replugin-plugin-gradle 插件和 replugin-plugin-lib 依赖:

    apply plugin: 'com.android.application'
    
    android {
        ...
    }
    
    apply plugin: 'replugin-plugin-gradle' // 集成 RePlugin 添加的配置
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:26.+'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.qihoo360.replugin:replugin-plugin-lib:2.2.1' // 集成 RePlugin 添加的配置
        testCompile 'junit:junit:4.12'
    }
    

    6:Androidmanifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.my.myreplugintest2">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
           == android:exported="true"==
    
            >
            <activity android:name=".MainActivity"
                android:theme="@style/AppTheme"
                >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
           == <!--插件名称-->
            <meta-data
                android:name="com.my.myreplugintest2.name"
                android:value="plugin1"/>
            <!--插件版本-->
            <meta-data
                android:name="com.my.myreplugintest2.version.ver"
                android:value="1"/>==
        </application>
    
    </manifest>
    

    设置成暴露exported="true",然后设置别名

    说明:meta-data下的name是包名+name,包名+version.var

    然后打成apk

    (内置于 APP 之中,并随 APP 一并发版,需要将插件 apk 改成 .jar 结尾放入主程序的assets/plugins目录。)

    7:主程序运行

    在主程序中与java文件同级,创建assets/plugins目录,把打好的apk修改名字为 plugin1.jar(plugin1是我的别名)

    RePlugin.startActivity(MainActivity.this, RePlugin.createIntent("plugin1", "com.my.myreplugintest2.MainActivity"));
    

    plugin1为插件别名。com.my.myreplugintest2.MainActivity是插件文件的位置。

  • 相关阅读:
    Perl Resources
    使用Perl管理Oracle数据库
    Tomcat 发布部署jsp网站—-使用自己的ip访问jsp网站
    Lode's Computer Graphics Tutorial Image Filtering
    Java Image Filters
    ZPhotoEngine超级算法库
    ps亮度对比度算法
    滤镜艺术---新海诚(你的名字)滤镜特效的实现解密
    Cocoa-GL-Tutorial
    Learning Cocoa with Objective-C
  • 原文地址:https://www.cnblogs.com/cmusketeer/p/9205865.html
Copyright © 2011-2022 走看看