插件开发:
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:插件和主程序所用的插件和依赖不一样,这个要仔细了