Replugin使用

插件开发:

1.配置项目根目录下的gradle:配置denpendencies

buildscript {
    repositories {
        mavenLocal()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.qihoo360.replugin:replugin-plugin-gradle:2.2.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


2.配置app目录下的gradle: 配置plugin和dependencies

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        versionName "1"
        versionCode 1
        targetSdkVersion 21
        applicationId "com.qihoo360.replugin.sample.demo1"
        minSdkVersion 15
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

// 这个plugin需要放在android配置之后,因为需要读取android中的配置项
apply plugin: 'replugin-plugin-gradle'

dependencies {
    compile 'com.qihoo360.replugin:replugin-plugin-lib:2.2.1'
}

3.配置清单文件:给activity单独配置theme

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.qihoo360.replugin.sample.demo1">

    <application
        android:allowBackup="false"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@android:style/Theme.Light.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

4.然后就可以开发插件了,插件开发完成后,得到apk文件,将apk文件的后缀名改为jar,copy到主程序的assets下的plugins文件夹下:



5.修改主程序下app目录下的gradle

apply plugin: 'replugin-host-gradle'
repluginHostConfig {
    useAppCompat = true

    // 可以在这里自定义常驻进程的名字
    // persistentName = ":XXXXService"
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.qihoo360.replugin:replugin-host-lib:2.2.1'
}

6.修改主程序下根目录的gradle:配置denpendencies

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
    classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}


7.自定义类继承RePluginApplication



8.配置清单文件:

<application
    android:name=".App"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

9.现在就可以在主程序中跳转到插件中的页面了,有多种跳转方式,下面的是包名跳转。

RePlugin.startActivity(MainActivity.this, RePlugin.createIntent("com.qihoo360.replugin.sample.demo1", "com.qihoo360.replugin.sample.demo1.MainActivity"));



ps:插件和主程序所用的插件和依赖不一样,这个要仔细了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值